I have this simple test website https://service-worker-test.app.baqend.com/ that displays 200 images next to eachother. It registers a very simple service worker. The HTML looks like this:
<html>
<style>
img {
width: 50px;
width: 50px;
float: left;
padding: 5px;
}
</style>
<head>
<title>Service Worker Test</title>
<script type="text/javascript">
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('sw.js');
}
</script>
</head>
<body>
<div class="row">
<img src="/img/1.jpg"/>
<img src="/img/2.jpg"/>
...
<img src="/img/200.jpg"/>
</div>
</body>
</html>
The service worker contains only a handler for the fetch event that prints out the url of the requests that it sees:
self.addEventListener('fetch', (event) => {
console.log('fetching: ' + event.request.url);
});
That's it. Now the first load in chrome installs the service worker. When I do the second load the service worker prints the HTML request and all 200 image requests to the console like this:
fetching: https://service-worker-test.app.baqend.com/
fetching: https://service-worker-test.app.baqend.com/img/1.jpg
fetching: https://service-worker-test.app.baqend.com/img/2.jpg
fetching: https://service-worker-test.app.baqend.com/img/3.jpg
....
fetching: https://service-worker-test.app.baqend.com/img/200.jpg
If I check the Disable Cache checkbox in the Network tab, all further loads do the same thing (make sure to clear the console after each load).
The problem now is: when the browser cache is not disabled, after a few loads the service worker will only print the following :
fetching: https://service-worker-test.app.baqend.com/
and nothing else. Also when debugging the service worker, only the HTML request is handled in the fetch event listener.
My question is why can't the service worker in chrome see requests when they are served from the browser cache?
Btw. the code works fine in firefox.
I'm using Chrome Version 59.0.3071.86 on Mac OS Version 10.11.6 (15G1421)