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 JS/CSS library bundle #10

Open
7 of 16 tasks
oandregal opened this issue Nov 20, 2017 · 16 comments
Open
7 of 16 tasks

Minimize JS/CSS library bundle #10

oandregal opened this issue Nov 20, 2017 · 16 comments

Comments

@oandregal
Copy link
Contributor

oandregal commented Nov 20, 2017

Current build size

Run npm run build:standalone and note down the sizes of these files in targets/standalone (note that the bundle analyzer reports a bit more). Then gzip -c file > file.gz to get the gzipped size.

Bundle Raw/Parsed Gzip
happychat.css 49K 8,9K
woo.css 760 304
jpop.css 758 317
happychat.js 412K 116K

Current bundle distribution (npm run analyze-bundles):

bundle-size-2018-06-28 14-34-58

These are the top-5 components by size:

  • react-dom: 90K parsed / 28K gzip.
    • How we use its API: to render the component tree & to findDomNode in some component. Can't be replaced for the managed library, but it wouldn't be necessary for a React/Redux env target (it could be externalized in that case).
  • src/ui: 67K parsed / 12K gzip
  • lodash: 36K parsed, 10K gzip.
  • src/state: 31K parsed, 6K gzip.
  • engine.io-client: 23K parsed, 8K gzip.

Some ideas to explore

Resources:

CSS

JS

@oandregal
Copy link
Contributor Author

Some stats to consider: GoogleChromeLabs/discovery#1

@oandregal
Copy link
Contributor Author

Parsing speed on mobile (moto G4) ~1Mb per second. Source: https://youtu.be/Fg7niTmNNLg

@oandregal
Copy link
Contributor Author

Check optimize-js in addition to minifiers: https://github.com/nolanlawson/optimize-js/blob/master/README.md

@oandregal
Copy link
Contributor Author

@oandregal
Copy link
Contributor Author

About bundles: different bundles for stuff that change frequently and stuff that doesn't so we can leverage the different caches in place - browsers (less network request time) and JS engines (less time to parse because they maintain a bytecode cache).

This was referenced Dec 15, 2017
@oandregal
Copy link
Contributor Author

After #32 and #34 this looks a lot better for JS: it's down to 0.8KB (~0.3KB minified) from 1.8MB.

@oandregal
Copy link
Contributor Author

#67 reduced CSS bundle from 70K to 40K.

@oandregal
Copy link
Contributor Author

#148 reduced the parsed size from 473K to 392K.

Before

current-bundle

After:

bundle-size-distribution-2018-03-02 19-17-51

@oandregal
Copy link
Contributor Author

#155 By removing our custom Gridicon build and use the Gridicons 3 (which allows us to import icons individually) we have reduced the raw/parsed size to 390K (a -2K improvement), and the gzipped to 112K (-1K improvement).

@oandregal
Copy link
Contributor Author

oandregal commented Mar 26, 2018

#174 reduced 10K the raw size and 3K the gzip size by not bundling certain lodash features we're not using. See.

Note that paths and shorthands are in use, so we've not dropped them. If we change the code to further remove those, we could reduce the raw size in 5K and the gzip size in 2K.

Before:

screenshot from 2018-03-26 21-05-59

After:

screenshot from 2018-03-26 20-59-44

@oandregal
Copy link
Contributor Author

#174 needed to be reverted in #182 it broke lodash usage in a few ways.

@oandregal
Copy link
Contributor Author

oandregal commented Apr 1, 2018

#187 has increased JS (+2K raw) and CSS (+4k raw and 2 new bundles for woo and jpop themes) bundle size. To introduce themes with CSS Custom Properties we need to polyfill for those browsers that yet don't support them.

bundle-size-2018-04-02 10-25-07

This was referenced Apr 1, 2018
@unDemian
Copy link
Contributor

unDemian commented Apr 2, 2018

The following PRs were merged Add support for npm package #184 #183 #180 #179 #178 #177 #176

Parsed Size Gzipped Size Analyze
Before 393.13 KB 112.75 KB https://cloudup.com/cvjPjefHXYj
After 397.3 KB 113.91 KB https://cloudup.com/ck-vWZqQPyR
Difference 4.17 KB 1.16 KB

@oandregal
Copy link
Contributor Author

As of June 26th, this is the size report:

screenshot from 2018-06-26 17-38-18

@oandregal
Copy link
Contributor Author

#243 has reduced bundle size in 70k parsed and 20K gzipped:

screenshot from 2018-06-26 17-50-37

@oandregal
Copy link
Contributor Author

oandregal commented Jun 28, 2018

By updating to React 16 in #249 we've reduced happychat.js size in 36K parsed (448K to 412K), and 11K gzipped (127K to 116K):

bundle-size-2018-06-28 14-34-58

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants