serviceservice-workerprogressive-web-appssw-precache

Why Precaching with fixed urls in manifest?


I was reading about precaching with service workers and i ended up with this precaching.

I cant understand why it uses fixed urls with hashes. They must be created dynamically every time a file changes.

So whats the point of putting them manually and setting revision to null?


Solution

  • If you are talking about the way Workbox tags the file hash value to the URL then I can answer this one.

    The hash is a calculation of the file contents. Which stays the same until you change anything in the file. Then the file has a different hash. So Workbox generates a manifest each time you run the script to generate the service worker.

    Then when the service worker is installed it will only fetch updates for network assets that have been updated. It can also do a hash check to verify the file is what is expects.

    Another way I have been accomplishing this without a manifest file and a build step to maintain is to make HEAD requests to the network assets. The server should return a last updated header value you can check against a value in the cache of when the file was created.

    I have not quite perfected this technique, but when I get it stable I will probably create an article about the method.

    But the ultimate goal is to eliminate as many round trips as possible and reduce the data burden on the server and the client.