[gatsby-plugin-offline]: Potential for caching problems with idb-keyval #24936
Labels
topic: plugins-PWA
Issues related to PWA: the gatsby-plugin-offline and gatsby-plugin-manifest plugins
type: bug
An issue or pull request relating to a bug in Gatsby
Description
I observed, that the plugin has an npm dependency to
idb-keyval
and copiesidb-keyval-iife.min.js
from the node_modules folder into the public folder inonPostBuild
:gatsby/packages/gatsby-plugin-offline/src/gatsby-node.js
Lines 163 to 166 in f8b7317
The official caching recommendations are oblivious of that file and it would be cached with
cache-control: public, max-age=31536000, immutable
.Furthermore, the plugin itself will cache the file with the
CacheFirst
strategy by default:gatsby/packages/gatsby-plugin-offline/src/gatsby-node.js
Lines 135 to 140 in f8b7317
This is based on the assumption that all
.css
and.js
files are fingerprinted, yetidb-keyval-iife.min.js
is not.If a future version of the plugin decides to use another version of
idb-keyval
this will become a problem since clients will not receive the update of the new version ofidb-keyval
because it is cached as immutable.Idea for a fix
Read the version of
idb-keyval
frompackage.json
innode_modules/idb-keyval
and include it in the filename. Instead of callingimportScripts
with a literal file name insw-append.js
, it could be prepended here with the filename that includes the version:gatsby/packages/gatsby-plugin-offline/src/gatsby-node.js
Lines 184 to 187 in f8b7317
This solves the problem without the need to alter any existing caching configurations. I can send a PR if this is wanted.
Environment
gatsby info --clipboard
yarn list | grep -E "(gatsby-plugin-offline|idb-keyval)" | grep -v deduped
The text was updated successfully, but these errors were encountered: