Description
Summary
The problem is that the revision
property on precaching is always set to the buildId
and changed on each build. This will cause an issue where the service worker will fetch ALL the pages on each build/release even the non-updated ones.
Next.js handles filenames hashing in a pretty convenient way using Webpack's contenthash
(e.g. [name].[contenthash].js
) which will only change the filename hash if the content of the file has changed.
And as described on Workbox docs here,
URLs that already include versioning information (like a content hash) are used as cache keys without any further modification.
By setting the revision
property to null
service worker will fetch only the updated pages on each build otherwise, it'll fetch all pages which will cause unnecessary network traffic.
Versions
next-pwa
: 5.4.1next
: 12.1.4
How To Reproduce
Steps to reproduce the behavior:
- Build the project with next-pwa
- run the app in production mode
- Monitor the network traffic, you'll see all the pre-cached files are fetched
- update one file in your project and build again
- run the app again, and you'll see all the pre-cached files are fetched again.
Link to minimal reproducing setup repository if any.
https://github.com/ammar-oker/next-pwa-example
Expected Behaviors
Allow developers to optionally set the revision
property to null
therefore, the filename hash is used as the cache key.