-
Notifications
You must be signed in to change notification settings - Fork 22
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
JavaScript optimizations #8
Comments
Optimization: Reduce bloated dependencies to keep JS payloads smaller.Step 1: MeasureWe start out by testing Of this, 1.7MB of the payload is JavaScript: Let's try running the production build to see how this changes. Thanks to Vue's usage of the Webpack performance budget feature, we're able to highlight [big] files: Lots of large PNGs/images but also a very large 2.16MB JavaScript vendor file. The rest of our application JavaScript is pretty small. We can use Lighthouse to analyze how we're doing on performance: We have large network payloads: A lot of the initial JS bootup costs are low because we aren't doing a whole lot when the app first starts. Most of the UI that gets executed is on the next route: And we can see that Parse/Compile of JS takes a few hundred milliseconds: But enormous payloads are still the biggest problem. Let's try analyzing this bundle in some more depth. Following https://code.luasoftware.com/tutorials/vuejs/vuejs-webpack-analyze-bundle-size/, we know we can run It gives us an output that looks like this: with the drawer That unicode (SO.js) module seems troublesome! The parsed cost is 1.64MB of code, which we know will take a few seconds to parse and gzipped that code is still ~93KB. Where do we use this module?
We go to our editor, and because we're using the BundlePhobia is a nice tool for finding out the consumption weight of different npm modules. We use it to test the slug module as follows: and can then try out alternatives. I find one called Limax which is 42KB gzipped: https://bundlephobia.com/result?p=limax@1.6.0 and another called https://bundlephobia.com/result?p=slugify@1.2.9 which is 4.2KB gzipped. Let's try that one. Step 2: OptimizeLooks pretty okay in editor and bundlephobia. Let's use the slugify module. When we make this change to our app, we can see that Vue's webpack build report changes: We have now saved 1.72MB on the size of the bundle and it's down to 444KB. This audit now passes the enormous payloads check in Lighthouse: and here's some bumps in performance metrics: Success 🎉 |
Optimization: Remove unused/unnecessary dependencies to reduce JS payload sizeOriginally, we made changes to our app because we were experimenting with using Material Design - cards, toolbars, nav. Later, once we decided to go more custom, we kept these imports in and they were bloating our bundle. We can also see that the Vue MDC adapter is taking up a chunk of our bundle: Looking back after the last optimization, we were at 444KB for the size of the bundle. Lighthouse audits for main thread consumption and JS bootup time: Dropping the MDC Web JavaScript only, we're able to trim the bundles down much more heavily. We can still use the CSS styles (which we import) as needed. We shaved off 327KB off our bundle. Everything seems to work as expected: Lighthouse wise, this takes us from this: to this: Our network payloads and JS bootup time are down |
…nto development * 'development' of https://github.com/google/io-demo-app: JS perf: Drop MVC JS from the bundle (#8) JS perf: switch from slug to slugify module
Roughly:
The text was updated successfully, but these errors were encountered: