Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

175 kb size? #650

Closed
screendriver opened this issue Feb 9, 2017 · 9 comments
Closed

175 kb size? #650

screendriver opened this issue Feb 9, 2017 · 9 comments

Comments

@screendriver
Copy link

screendriver commented Feb 9, 2017

I added kinto.js to my project (see also #649) as a npm dependency and saw that it increased my final bundle file size about 175 kb in size 😳

Is there anything I can do to reduce it's size? It seems a little bit too large in my eyes compared to other libraries / frameworks.

@Natim
Copy link
Member

Natim commented Feb 9, 2017

I guess it depends of how much polyfill you want to have in it.

@leplatrem
Copy link
Contributor

Thanks for the feedback!

I agree that packaging could be improved, especially to get rid of babel from dependencies.

The codebase is not big at all and it only relies on btoa, kinto-http and uuid. I think isomorphic-fetch could be removed too from kinto-http deps too.

And now that modern browsers support natively async/await, the only transformation could be CommonJS modules for browsersify.

I can't spend much time to work on this those days, but we'd be happy to help if you start something in a PR

@screendriver
Copy link
Author

I guess it depends of how much polyfill you want to have in it.

That's the point. I think that a library should not contain any polyfills. The consuming environment should make sure that everything is available at runtime. A library should have as few as possible dependencies.

For example In my project I don't include the huge babel-polyfill. I only include the polyfills that I really use (for example core-js/es6/promise and whatwg-fetch).

And now that modern browsers support natively async/await, the only transformation could be CommonJS modules for browsersify.

Thats true. Same here: if the library writes code in the shiny new async and await fashion the consuming project should ensure that everything gets transpiled for older browser (or not if I don't want to)

I try to make a work in progress pull request these days for all that. I hope I've got enough time 😉

@Natim
Copy link
Member

Natim commented Feb 9, 2017

I agree with you let's improve that 👍

@leplatrem
Copy link
Contributor

I just released kinto-http.js v3.0 which gets rid of the isomorphic-fetch polyfill

@screendriver
Copy link
Author

Oh that was quick 👍

Currently I am thinking about if it would make sense to just publish the "raw" ES2015 code as it's written to npm and not the transpiled one.

Advantages

  1. the consuming project has full control over how it gets transpiled (Babel, TypeScript, Webpack, Brunch, Rollup.js, SystemJS and so on)
  2. Tree Shaking would then be possible
  3. kinto.js shrinks to just a few bytes
  4. Debugging with source maps would be much more easier because the module bundler of the consuming project can generate it

Disadvantages

Only one: the consuming project must use a transpiler to use kinto.js

Hmmm... 🤔

@n1k0
Copy link
Contributor

n1k0 commented Feb 9, 2017 via email

@screendriver
Copy link
Author

But when we publish the src directory there are still all requires to Babel related stuff.

At the moment I am searching for best practices / design patterns for library authors that have the same problem like kinto.js.

@dstaley
Copy link
Member

dstaley commented May 9, 2020

With v13, our bundle size has now dropped to ~15 KB gzipped! 🎉

@dstaley dstaley closed this as completed May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants