Skip to content

Commit

Permalink
fix(gatsby-plugin-offline): versioned import of idb-keyval (#24938)
Browse files Browse the repository at this point in the history
* fix(sw): versioned import of idb-keyval

with the version included it is ok to cache it immutable alongside the other fingerprinted js files produced by Gatsby

* style: fix linting errors

* fix(sw): replace versioned import in sw-append.js
  • Loading branch information
nibtime authored Jun 18, 2020
1 parent c884b0d commit 13aaa16
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/gatsby-plugin-offline/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ exports.onPostBuild = (

const idbKeyvalFile = `idb-keyval-iife.min.js`
const idbKeyvalSource = require.resolve(`idb-keyval/dist/${idbKeyvalFile}`)
const idbKeyvalDest = `public/${idbKeyvalFile}`
const idbKeyvalPackageJson = require(`idb-keyval/package.json`)
const idbKeyValVersioned = `idb-keyval-${idbKeyvalPackageJson.version}-iife.min.js`
const idbKeyvalDest = `public/${idbKeyValVersioned}`
fs.createReadStream(idbKeyvalSource).pipe(fs.createWriteStream(idbKeyvalDest))

const swDest = `public/sw.js`
Expand All @@ -183,6 +185,7 @@ exports.onPostBuild = (

const swAppend = fs
.readFileSync(`${__dirname}/sw-append.js`, `utf8`)
.replace(/%idbKeyValVersioned%/g, idbKeyValVersioned)
.replace(/%pathPrefix%/g, pathPrefix)
.replace(/%appFile%/g, appFile)

Expand Down
3 changes: 1 addition & 2 deletions packages/gatsby-plugin-offline/src/sw-append.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* global importScripts, workbox, idbKeyval */

importScripts(`idb-keyval-iife.min.js`)
importScripts(`%idbKeyValVersioned%`)

const { NavigationRoute } = workbox.routing

Expand Down

0 comments on commit 13aaa16

Please sign in to comment.