Logo

dev-resources.site

for different kinds of informations.

Stop Bundling Scripts for Better Web Performance

Published at
4/6/2020
Categories
webperf
javascript
webdev
serviceworkers
Author
fleshmecha
Author
10 person written this
fleshmecha
open
Stop Bundling Scripts for Better Web Performance

Here's the conventional advice:

for a fast webpage, split your code and bundle it.

This advice did not work for me.

Whenever I split my code into manageable subsets, the page broke. I still bundled my code to reduce HTTP requests (using Netlify's post processing), and my page loaded in over 2 seconds, with 1.5 seconds being dedicated to the huge bundled script. Not acceptable. Shouldn't reducing HTTP requests lead to a faster page? This is web performance gospel - reduce HTTP requests!

My page speed while bundling scripts

I did have a service worker that was caching static assets for me, but the caching only increased page speed because those static assets were never used in the cached form.

The service worker would cache sea.js, but since sea.js was bundled with webrtc.js and jquery.min.js in production, that cached asset never saw the light of day.

I think you can see where I'm going with this. Unbundle!

Page speed while unbundling scripts

After unbundling the scripts, all of them loaded asynchronously in under 50 ms.

From 1.5 seconds of loading to 50 ms loading.

The whole page loaded in 77ms. Wow.

This speed increase from unclicking one button on Netlify's post-processing options was too incredible for me not to share.

Of course, this post assumes you are using a service worker to pre-cache static assets. If you're not, you can read the documentation to learn why service workers are useful and follow some tutorials.

I have Lighthouse, YSlow, and PageSpeed scores of 100 across the board, largely because of service workers.

This is my first DEV post. Let me know what you think!

serviceworkers Article's
30 articles in total
Favicon
Service Workers: Revolutionizing Modern Web Apps
Favicon
Building Progressive Web Apps in Angular (using pwafire)
Favicon
Leveraging Service Workers for Advanced Caching Strategies in PWA: A Deep Dive for Beginners
Favicon
Integrating the Cache API with Service Workers
Favicon
Service worker weirdness in Chrome
Favicon
When service workers met framesets
Favicon
JS Service Workers — An Introduction
Favicon
Service workers in create-react-app v4+
Favicon
Offline caching with serviceworkers
Favicon
Why is an external service via internet, e.g. web-push with GCM needed for service workers to push notifications?
Favicon
Stop Bundling Scripts for Better Web Performance
Favicon
Does dev.to ever just hang and not load for you?
Favicon
Service workers con Workbox 3, tu primera vez
Favicon
Recreando el Parqués/Parchis en ReactJS - Primera Parte
Favicon
Recreando el Parqués/Parchis en ReactJS - Segunda Parte
Favicon
Build a Better Web with Service Workers
Favicon
Turn your angular application into PWA through service worker
Favicon
How to Get Videos to Work in Safari With Gatsby and Service Workers
Favicon
Who's using Service Workers?
Favicon
My MVP that's PWA and SPA with just wordpress. I'm seeing 0.5s loads, would adding service workers improve performance?
Favicon
Let Users Know When You Have Updated Your Service Workers in Create React App
Favicon
Help: Should a new service worker force a refresh to update a PWA?
Favicon
Going offline with IndexedDB
Favicon
sw-tools, a library to rule the Service Workers
Favicon
How to optimize your JavaScript app by using service workers
Favicon
Progressive Web Apps: Caching Strategies
Favicon
Paying Attention while Loading Lazily
Favicon
Launching: Push Notifications For Everyone!
Favicon
What service workers are being used on dev.to and what do they do?
Favicon
Steam Roulette

Featured ones: