my gatsby site on netlify doesnt get refreshed on update

Viewed 527

i am using the gatsby netlify plugin like this:

      resolve: `gatsby-plugin-netlify`,
      options: {
        headers: {
          "/*.js": [
            "cache-control: public, max-age=31536000, immutable",
          ],
          "/*.css": [
            "cache-control: public, max-age=31536000, immutable",
          ],
          "/sw.js": [
            "cache-control: public, max-age=0, must-revalidate",
          ],
        },
      },

    },

However, when i publish an update to the site, the browser doesnt see it until 'refresh' is manually hit. simply visiting the site (without hitting refresh) shows the old version.

1 Answers

If you are having service worker caching issues you like this, you need to install the gatsby-plugin-remove-serviceworker into your application that will remove the service worker for you. This will do the work you are trying to do in the netlify config above.

It's super easy to set up - just add it to the gatsby-config.js near the bottom of your application:

module.exports = {
  siteMetadata: {
    title: 'Your site',
  },
  plugins: [
    // Gets rid of the service worker 
    'gatsby-plugin-remove-serviceworker'
  ]
}
Related