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

Minimize the browserified size #89

Closed
sindresorhus opened this issue Jul 24, 2015 · 10 comments
Closed

Minimize the browserified size #89

sindresorhus opened this issue Jul 24, 2015 · 10 comments
Labels
enhancement This change will extend Got features ✭ help wanted ✭

Comments

@sindresorhus
Copy link
Owner

Turns out some people use this with browserify, but by default got is huge when browserified, since it includes the buffer browser polyfill and other things. We should look into if there's any way to get it down without too much work.

Relevant: https://twitter.com/mattdesl/status/624703076159590400

Not sure, but this might be useful: https://github.com/miguelmota/buffer-to-arraybuffer

@floatdrop
Copy link
Contributor

Full list of browserified modules: https://gist.github.com/floatdrop/acfb074b261288655e45

Top of size-eaters:

  • browserify-zlib is 173.3 Kb f9f2807
  • duplexify is 64.9 Kb
  • buffer is 43.7 Kb

@mattdesl
Copy link

👍

I started got-xhr for this reason but haven't published it yet. If possible, I would rather build on an existing module than add more clutter to npm.

But with that said, it might be necessary to have a separate got-like module that has a more limited scope than got. Things like:

  • avoiding Buffer, and instead using ArrayBuffer since it is more common in the browser
  • avoiding zlib, since the browser handles gzip for us anyways (from what I understand?)
  • avoiding streams entirely since they add a pretty significant amount of bloat
  • just using xhr under the hood

@mattdesl
Copy link

mattdesl commented Sep 3, 2015

Update: I'm now using xhr-request in node/browser for non-streamed requests.

For streamed requests, simple-get is pretty good, and half the size of got.

got could probably be almost as small as simple-get by doing something like this:
https://github.com/feross/simple-get/blob/d212b1022d21b49c8ec83acf251d1dc4aeb38ca3/package.json#L10-L12

@kevva
Copy link
Contributor

kevva commented Oct 2, 2015

66542fd reduced the size from 471 KB to 268 KB, thanks @mattdesl.

@floatdrop floatdrop added the enhancement This change will extend Got features label Oct 15, 2015
@floatdrop
Copy link
Contributor

With 6.0.0 version got is almost same size as simple-get, but still 10x bigger than xhr.

❯ browserify -r got | wc -c
  207787

❯ browserify -r simple-get | wc -c
  194566

❯ browserify -r xhr | wc -c
  11147

@sindresorhus
Copy link
Owner Author

@floatdrop Woot! Try gzipping too. That gives more accurate numbers.

@mattdesl
Copy link

mattdesl commented Jan 7, 2016

Nice!

gzip can be misleading when you are considering how bundle size affects parse/execution time. 😄

More details:
https://timkadlec.com/2014/09/js-parse-and-execution-time/

@mattdesl
Copy link

mattdesl commented Jan 7, 2016

But you should probably include uglifyjs -cm to get a better idea.

@mattdesl
Copy link

mattdesl commented Jan 7, 2016

p.s. You can't run got through uglify-js right now because it has some ES6-isms (which also means it will break on safari, IE and the likes).

browserify -r got | uglifyjs -cm | wc -c
Parse error at -:7172,5
Unexpected token: name (redirectCount)
Error
    at new JS_Parse_Error (eval at <anonymous> (/Users/matt/npm/lib/node_modules/uglify-js/tools/node.js:22:1), <anonymous>:1526:18)
   ...

@thisconnect
Copy link
Contributor

@mattdesl about Unexpected token: name (redirectCount) it is caused by let, see mishoo/UglifyJS#887

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This change will extend Got features ✭ help wanted ✭
Projects
None yet
Development

No branches or pull requests

5 participants