goldhand / sw-precache-webpack-plugin

Webpack plugin that generates a service worker using sw-precache that will cache webpack's bundles' emitted assets. You can optionally pass sw-precache configuration options to webpack through this plugin.
MIT License
1.44k stars 105 forks source link

How to set maxAge for service worker? #143

Closed AndreasGalster closed 6 years ago

AndreasGalster commented 6 years ago

I'm submitting a support request

webpack version: 3.5.5

sw-precache-webpack-plugin version: 0.11.4

Please tell us about your environment: Ubuntu prod server 16.04, testing with Windows Chrome 54

I've successfully implemented a service worker via the plugin, however I noticed that the service worker is cached for a day. It seems that the common practice is to set the maxAge of the service worker file to be 0, so I followed this advice:

app.use('/sw.js', express.static(__dirname + '/build/sw.js', {maxAge: 0}));

Which doesn't seem to work though, am I doing something wrong or is there a way to define the maxAge of the service worker directly via the plugin?

goldhand commented 6 years ago

This depends on your content delivery method. express has a way to specify an http header but browsers are planning to force this header in the future anyway so I would just make sure you don't cache the service-worker accidentally.