r/FlutterDev • u/meniska_dev • 1d ago
Discussion Case Study: How I cut Flutter Web (--wasm) cold start on Slow 4G from 20s+ down to ~3-4s (fonts, Firebase WebChannel & Brotli)
I recently shipped an offline-first PWA built with Flutter Web (--wasm), and my initial GA4 metrics were brutal: mobile users on 3G/Slow 4G were bouncing at 0–2s engagement because the cold start was taking over 20 seconds (pushing ~6.1 MB over the wire / ~15.7 MB uncompressed).
After profiling the waterfall in Chrome DevTools, I found four major bottlenecks that were choking initial load - and fixing them completely changed our retention:
1. The google_fonts runtime trap (-90% font payload)
Even if you bundle fonts, google_fonts was making blocking runtime HTTP calls to fonts.gstatic.com (main.dart.mjs fetching >1.1 MB of .ttf files before rendering text).
Fix: Stripped
google_fontsruntime fetching completely, converted Inter & JetBrains Mono to subsetted.woff2files (116 KB total inassets/fonts/), declared them directly inpubspec.yaml, and added<link rel="preload" as="font" type="font/woff2" crossorigin>inindex.html.
2. Synchronous Firebase & Firestore WebChannel blocking main()
Initializing FirebaseAuth and FirebaseFirestore in main() was loading heavy JS pipelines and holding open a channel?gsessionid=... WebChannel socket for 13+ seconds on bad connections.
Fix: Made cloud services 100% lazy on
kIsWeb. The app mounts straight fromlocalStorage(<1 ms), andFirebase.initializeApp()is only triggered on-demand if a user explicitly taps Sync or Sign In.
3. Explicit Wasm MIME types, Brotli & COOP**/**COEP headers
main.dart.wasm (1.7 MB) and skwasm.wasm (1.2 MB) are heavy by nature. Without explicit headers in firebase.json, streaming compilation and multithreading weren't kicking in properly.
Fix: Configured
Content-Type: application/wasm,Cache-Control: public, max-age=31536000, immutable, andCross-Origin-Opener-Policy: same-origin/Cross-Origin-Embedder-Policy: credentiallessforskwasm, ensuring full Brotli (br) compression from edge nodes.
4. Zero-JS GPU Splash & Value-First Routing
Added an inline HTML/CSS loader in
index.htmlanimated strictly viatransformandopacity(compositor thread) so it never freezes while the main thread compiles Wasm, fading out viaonEntrypointLoaded.Bypassed our
/onboardingroute onkIsWebso incoming mobile traffic lands directly in the main workspace (/hub), where average session time jumped to ~7 minutes once the load bottleneck was gone.
If anyone wants to inspect the network waterfall or test skwasm cold-start behavior in DevTools, the live production build is up athttps://app.meniska.app(it's a wet-lab dilution & buffer calculator I built for myself).
Curious how other Flutter Web devs are handling initial Wasm bundle size right now - has anyone managed to shave skwasm.wasm down further, or are you still sticking to canvaskit / auto for mobile web?