File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ module.exports = function nuxtWorkbox (moduleOptions) {
21
21
debug ( 'Adding workbox' )
22
22
const options = getOptions . call ( this , moduleOptions )
23
23
workboxInject . call ( this , options )
24
+ setHeaders . call ( this , options )
24
25
emitAssets . call ( this , options )
25
26
addTemplates . call ( this , options )
26
27
}
@@ -178,4 +179,27 @@ function workboxInject (options) {
178
179
}
179
180
}
180
181
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 ( / s w \. j s $ / ) ) {
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
+
181
205
module . exports . meta = require ( './package.json' )
You can’t perform that action at this time.
0 commit comments