mercredi 29 janvier 2020

Why does an empty service worker significantly slow down page load speed?

A very simple setup.

  1. Importing service worker file within <script> tag in index.html like so:
if ('serviceWorker' in navigator) {
    window.addEventListener('load', function() {
        navigator.serviceWorker.register('/app/static/js/service-worker.js', { scope: '/' });
    });
}
  1. Service worker itself is empty (1 line):
console.log('Successfully Installed Service Worker.');
  1. After running page load speed tests I get interesting results:
                        DOM Interactive    DOM Complete       Load Event End     Number of page loads
no-service-worker       0.232              2.443              2.464              30
with-service-worker     0.343              2.484              2.502              30

What gives? How does an empty service worker slow down page load by whopping 120+ milliseconds?




Aucun commentaire:

Enregistrer un commentaire