Remy continues to tweak his implementation of his service worker. In this iteration he ensures that if you land directly on a blog post for the first visit (when the service worker is first activated) that the current page is added to the list of cached items (it doesn’t by default because when the page was requested the service worker hadn’t been installed yet).
When my service worker installs, I add some “sensible defaults” to the browser’s cache:
- The index page
- My CSS
- Four core images
The rest is cached on demand. However, the page that triggered the installation, likely to be a blog post, won’t be in the cache because the first request for that resource was performed through the browser’s native network handling and not through my service worker.
So, how do I work around this?An excerpt from Blog service workers and the chicken and the egg