Description
A consistent piece of feedback I hear from teams building PWAs is that Webpack configs are a major pain point. In particular, knowing what Webpack-specific performance best practices (and plugins) to follow are or what to use for patterns like PRPL.
Is there value in us having a dedicated page to this topic in the docs, even if some of it involves linking out to existing docs? 🙃
I might loosely break these up into a few different buckets:
- "Ship the minimal code to make a page useful"
- Code-splitting (basic, vendor, aggressive, avoiding module duplication)
- Using
webpack-bundle-analyzer
to find and fix low hanging fruit in bundles - Staying on top of your perf over time with the Webpack 2.x perf budgets feature
- "Prioritize resources you know are important"
- Preload bundles to improve perf with
link rel=preload
. How to do this manually or with a webpack plugin - HTTP/2 Server Push to fill up server think time. We have the aggressive splitting plugin, but nothing Webpack specific I can think of that helps with Push manifest generation. Maybe just directly use https://github.com/GoogleChrome/http2-push-manifest?
- Preload bundles to improve perf with
- "Be network resilient!" with Service Workers
- Offline static asset caching (sw-precache-webpack-plugin, offline-plugin)
- "Don't double up your parse costs with CSS-in-JavaScript"
- Use the
ExtractTextPlugin
to extract CSS into separate files. Avoids 2x memory costs, parse costs and invalidating cachability of JS each time your CSS changes. Some projects (e.g styled components) don't tackle this problem well just yet.
- Use the
- "Effectively use the browser cache"
- Long-term caching (Working around runtime/chunk lookups being moved into the vendor bundle & losing long-term caching on each build/deploy)
Related
We're working on some related scaffolding + PWA pieces over on webpack-cli
References
Some PWA teams have been documenting their Webpack configs in public, like this one. We've also got quite a few Webpack configs in use for the HN apps over here: https://github.com/tastejs/hacker-news-pwas
Wrote about some of this stuff in the PWAs with React series.
Twitter Lite's isn't too different but they're on WP1. They're using DedupePlugin(), OccurrenceOrderPlugin, BundleAnalyzer, CircularDependencyPlugin, StatsPlugin.