Webhook is not clearing cache

Hi. It seems the Gatsby Cloud build webhook isn’t clearing the cache before building.
This means my application (which is cached inside the browser) will never update to the newly build application, unless I manually select “clear cache and build” in my Gatsby Cloud dashboard.

What can I do to make the cache clear automatically before building?

This is not true. The clear cache option clears the build cache (the one stored on Gatsby Cloud and consists of your build dependencies, among other things). It has nothing to do with your browser cache. The browser cache would be automatically invalidated.

My Gatsby application is cached for offline use with gatsby-plugin-offline.
I used these functions (moderated from standard Gatsby code found on StackOverflow) to get the application to update whenever there’s a route change:

export const onRouteUpdate = ({ location, prevLocation }) => {
  //register the service worker and update the app
  if ('serviceWorker' in navigator) {
    navigator.serviceWorker.register('/sw.js').then((reg) => {
      reg.update();
    })
      .catch((e) => {
        console.log("Error! : ", e)
      })
  }
  else {
    console.log('service workers are not supported.');
  }
}

// update the app if available
export const onServiceWorkerUpdateReady = () => {
  console.log("updating app ..");
  window.location.reload(true)
}

Only when I manually pick “clear cache and build” on Gatsby Cloud can I be (almost) certain that the service worker will actually reinstall and clear its cache.

Is it possible that building on Gatsby Cloud without using “clear cache and build” doesn’t update the service worker file (sw.js), and because of this, “reg.update()” doesn’t do anything?

Again, please stop confusing clear cache and build option with the cache in the browsers. Those 2 are completely un-related.

Service worker cache cannot be cleared from the server. Service Workers fall under custom-code and we do not provide support about those. You need to make sure they are working as you expect them to.