Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewhartman/38d513fa2d6a66adcfade32f7eaed5f8 to your computer and use it in GitHub Desktop.
Save matthewhartman/38d513fa2d6a66adcfade32f7eaed5f8 to your computer and use it in GitHub Desktop.
Generate New Service Worker Version
// https://mydevhack.com/post/automatically-generate-a-new-service-worker-version
const fs = require('fs')
// Create new version
const version = new Date().getTime()
// Write new version to service worker
fs.readFile('sw.js', 'utf8', function (err,data) {
if (err) {
return console.log(err)
}
var result = data.replace(/var CACHE_NAME = .+/g, `var CACHE_NAME = 'v-${version}'`)
fs.writeFile('sw.js', result, 'utf8', function (err) {
if (err) return console.log(err)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment