Permalink
Browse files

feat(workbox): disable caching for sw.js by default

  • Loading branch information...
manniL committed Jul 22, 2018
1 parent 76de33c commit e7677d8c317aa4c189dfe563a2ec5e279d53d691
Showing with 24 additions and 0 deletions.
  1. +24 −0 packages/workbox/index.js
@@ -21,6 +21,7 @@ module.exports = function nuxtWorkbox (moduleOptions) {
debug('Adding workbox')
const options = getOptions.call(this, moduleOptions)
workboxInject.call(this, options)
setHeaders.call(this, options)
emitAssets.call(this, options)
addTemplates.call(this, options)
}
@@ -178,4 +179,27 @@ function workboxInject (options) {
}
}
// =============================================
// setHeaders
// =============================================
function setHeaders (options) {
if (options.customHeaders) {
return
}
const originalSetHeadersMethod = this.options.render.static.setHeaders
this.options.render.static.setHeaders = (res, path) => {
if (path.match(/sw\.js$/)) {
// Prevent caching service worker
res.setHeader('Cache-Control', 'no-cache')
} else {
if (typeof originalSetHeadersMethod !== 'undefined') {
originalSetHeadersMethod(res, path)
}
}
}
}
module.exports.meta = require('./package.json')

0 comments on commit e7677d8

Please sign in to comment.