Automattic / happychat-client

Happychat customer client code
13 stars 5 forks source link

Minimize JS/CSS library bundle #10

Open oandregal opened 6 years ago

oandregal commented 6 years ago

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:

Some ideas to explore

Resources:

CSS

JS

oandregal commented 6 years ago

Some stats to consider: https://github.com/GoogleChromeLabs/discovery/issues/1

oandregal commented 6 years ago

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

oandregal commented 6 years ago

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

oandregal commented 6 years ago

Might contain useful info: https://medium.com/reloading/javascript-start-up-performance-69200f43b201

oandregal commented 6 years ago

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).

oandregal commented 6 years ago

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

oandregal commented 6 years ago

https://github.com/Automattic/happychat-client/pull/67 reduced CSS bundle from 70K to 40K.

oandregal commented 6 years ago

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

Before

current-bundle

After:

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

oandregal commented 6 years ago

https://github.com/Automattic/happychat-client/pull/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 commented 6 years ago

https://github.com/Automattic/happychat-client/pull/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 commented 6 years ago

174 needed to be reverted in https://github.com/Automattic/happychat-client/pull/182 it broke lodash usage in a few ways.

oandregal commented 6 years ago

https://github.com/Automattic/happychat-client/pull/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

unDemian commented 6 years ago

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 commented 6 years ago

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

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

oandregal commented 6 years ago

https://github.com/Automattic/happychat-client/pull/243 has reduced bundle size in 70k parsed and 20K gzipped:

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

oandregal commented 6 years ago

By updating to React 16 in https://github.com/Automattic/happychat-client/pull/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