Skip to content

Commit e7677d8

Browse files
committedJul 22, 2018
feat(workbox): disable caching for sw.js by default
1 parent 76de33c commit e7677d8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
 

‎packages/workbox/index.js

+24
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = function nuxtWorkbox (moduleOptions) {
2121
debug('Adding workbox')
2222
const options = getOptions.call(this, moduleOptions)
2323
workboxInject.call(this, options)
24+
setHeaders.call(this, options)
2425
emitAssets.call(this, options)
2526
addTemplates.call(this, options)
2627
}
@@ -178,4 +179,27 @@ function workboxInject (options) {
178179
}
179180
}
180181

182+
// =============================================
183+
// setHeaders
184+
// =============================================
185+
186+
function setHeaders (options) {
187+
if (options.customHeaders) {
188+
return
189+
}
190+
191+
const originalSetHeadersMethod = this.options.render.static.setHeaders
192+
193+
this.options.render.static.setHeaders = (res, path) => {
194+
if (path.match(/sw\.js$/)) {
195+
// Prevent caching service worker
196+
res.setHeader('Cache-Control', 'no-cache')
197+
} else {
198+
if (typeof originalSetHeadersMethod !== 'undefined') {
199+
originalSetHeadersMethod(res, path)
200+
}
201+
}
202+
}
203+
}
204+
181205
module.exports.meta = require('./package.json')

0 commit comments

Comments
 (0)
Please sign in to comment.