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'
}
}
]
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.
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.
# 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.
You are most likely running into a common double caching situation, refer to this Cache Control and upcoming changes in Chrome Fresher Service Workers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With