Skip to content

Allow revision property to be null on preaching #336

Closed
@okerx

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.1
  • next: 12.1.4

How To Reproduce

Steps to reproduce the behavior:

  1. Build the project with next-pwa
  2. run the app in production mode
  3. Monitor the network traffic, you'll see all the pre-cached files are fetched
  4. update one file in your project and build again
  5. 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.

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdone

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions