Skip to content

Commit

Permalink
feat(workbox): disable caching for sw.js by default
Browse files Browse the repository at this point in the history
  • Loading branch information
manniL committed Jul 22, 2018
1 parent 76de33c commit e7677d8
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/workbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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.