Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Network first caching of index.html using workbox.js

I've integrated a service worker into our Single Page App built with ReactJS, using the workbox-build package by Google.

I'm having some troubles on the pre-caching of the index.html, specifically the service worker is serving an outdated index.html everytime we release a new build. Since it served an outdated index.html, the main JavaScript file is not found since it is versioned based on the build.

</div><script type="text/javascript" src="/static/js/main.fa34a3ce.js"></script>

I have also tried to remove the index.html from pre-cache, and have it in the runtime cache with a network first setting. But it doesn't seem to be cached by the service worker.

runtimeCaching: [
  {
    urlPattern: /\/$/,
    handler: 'networkFirst',
    options: {
      cacheName: 'my-cache-index'
    }
  }
]
like image 957
Adrian Avatar asked Apr 25 '18 07:04

Adrian


People also ask

What is self __ Wb_manifest?

Note the self.__WB_MANIFEST string. This is a placeholder that Workbox replaces with the precache manifest. Below is a valid configuration for this use case: // build-sw.js.

What is JS workbox?

Workbox is a set of modules that simplify common service worker interactions such as routing and caching. Each module addresses a specific aspect of service worker development.

What is Cache first strategy?

# Cache first, falling back to network The request hits the cache. If the asset is in the cache, serve it from there. If the request is not in the cache, go to the network. Once the network request finishes, add it to the cache, then return the response from the network.


1 Answers

You are most likely running into a common double caching situation, refer to this Cache Control and upcoming changes in Chrome Fresher Service Workers.

like image 156
Dean Taylor Avatar answered Oct 21 '22 07:10

Dean Taylor