Search code examples
htmlprogressive-web-appsservice-workerworkbox

Workbox - Files served from Cache by Service Worker even if caching strategy used is NetworkOnly


I am using Workbox for PWA in my project. As a caching strategy, I am using NetworkOnly from workbox.strategies.NetworkOnly class. From what I understand, Network Only means that ServiceWorker will always request files from server and not from cache. However, when I look in the network tab, the files seem to be served from cache by ServiceWorker.

Is there anything wrong in my understanding?

Please refer to screenshot of code snippets below: enter image description here

enter image description here


Solution

  • The network tab will show "ServiceWorker" as the source regardless if the server worker used a cache or the network to fetch the resource.

    If you want to test if a resource is being served from the network only you can switch to offline mode and see if those resources fail to load. Additionally if the service worker is fetching a resource from the network the resource will show up on the network list twice. Once between the client and the service worker and once between the service worker and the server. You can see bundle.min.js is listed twice so it's being fetched from the network.