cozy / cozy-keys-lib

GNU General Public License v3.0
0 stars 1 forks source link

Lighten the bundle size #170

Open paultranvan opened 3 years ago

paultranvan commented 3 years ago

According to this analyzer, cozy-keys-lib's bundle takes 426 Ko. We could gain some space by removing heavy and dispensable libs, typically node-forge or tld.js. Previous work like https://github.com/cozy/cozy-keys-lib/pull/43 already improved the weight, although not everything went as planned: https://github.com/cozy/cozy-keys-lib/pull/73

tldjs is used to get the domain which can be easily reimplemented in a stub see its definition

node-forge (which can actually be used in browser, despite the name) is used for two things:

  1. support for old browsers that does not have subtle crypto API, such as IE or old Safari
  2. "fast" crypto operations, brought by this commit. It is unclear how it is fast compared to the subtle API and how useful it actually is

The 1. does not seem to be a problem, as we officially does not support IE, and only support Safari >=12, which support subtle API. About 2., this require to keep most of the existing node-forge imports, but newer jslib's versions seem to remove this need.

Crash-- commented 3 years ago

Stubbing getDomain from tldjs is not as easy as it can seems.

When the JSLib request getDomain it gets this one https://github.com/oncletom/tld.js/blob/b758887c0d01a12b6c0f048a544377e8d44368db/index.js#L114 . And this one call parse and parse need to have the rules.json file.

Ldoppea commented 3 years ago

Do you have an idea of how much weight we can save?

but newer jslib's versions seem to remove this need.

The methods you linked have not been edited for 4 years 🤔

cozy-keys-browser is using a recent jslib version from july 2021. cozy-pass-web is using one from may 2021. Maybe it would be a good idea to update cozy-keys-lib's one. Also I may need to do it soon if I expect to mutualise recent changes from cozy-keys-browser and cozy-pass-web.