Support Forums

Sw never updates site after changing primary domain from apex to www

Im running a gatsby site on https://exclusieveauto.netlify.app/
I recently changed the primary domain from apex to www.exclusieveauto.nl

Whenever I visit the apex website, I get the cached website (probably because of gatsby-plugin-offline) with a bunch of CORS errors like:

Access to fetch at 'https://www.exclusieveauto.nl/page-data/app-data.json' (redirected from 'https://exclusieveauto.nl/page-data/app-data.json') from origin 'https://exclusieveauto.nl' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

at a point the gatsby site will crash because it’s not loading data properly.

What actually should happen, is that the user gets redirected to www. But because I have visited the website before and have the serviceworker i am stuck? I don’t know actually at what level that redirect should happen…

Any help is welcome

I’m not seeing the error you mention:

I’m trying to load the apex domain, but get redirected to the www one.

yes it only happens when you have visited the website before the primary domain was changed to www

I am actually not being redirected to www on the machines I’ve visited this site in the past with. When I go incognito, I get redirected.

If that’s the case, I’d advise to remove the service worker for now.

I guess that would maybe fix it, but when would I ever be able to add it again? After every user that has visited my site before has the SW uninstalled? So never?

You could programatically remove a service worker and remove its cache too. But yes, that won’t work if the user visits only the page that’s cached. You could create a new page and add a redirect to send users to that page just to remove the service workers and redirect back to the previous page. Definite not the perfect solution, but that’s the problem with service workers. if not configured correctly, they add more problems than they solve.

1 Like