admin管理员组文章数量:1279211
I have a website which was using gatsbyJS (React framework for static sites)
Now I have moved the site to a CMS (WordPress) but because we have used gatsbyJS initially on the same domain, it's showing old cached files that gatsby has built.
we are not able to access the new website on browsers where someone has initially opened the gatsby site, as its just showing the cached files.
From my initial search I came to know following things:
- GatsbyJS is optimized for offline access using
service workers
. - To invalidate the service workers, I need to again server the GatsbyJS static site after adding some script so that when someone visits the site, service workers gets invalidated.
- I can't control service workers otherwise.
I can't go back to initial site as that's already been published and people are looking at it but there are many other people who are still seeing the broken gatsby site.
any solution for the above issue?
I have a website which was using gatsbyJS (React framework for static sites)
Now I have moved the site to a CMS (WordPress) but because we have used gatsbyJS initially on the same domain, it's showing old cached files that gatsby has built.
we are not able to access the new website on browsers where someone has initially opened the gatsby site, as its just showing the cached files.
From my initial search I came to know following things:
- GatsbyJS is optimized for offline access using
service workers
. - To invalidate the service workers, I need to again server the GatsbyJS static site after adding some script so that when someone visits the site, service workers gets invalidated.
- I can't control service workers otherwise.
I can't go back to initial site as that's already been published and people are looking at it but there are many other people who are still seeing the broken gatsby site.
any solution for the above issue?
Share Improve this question asked Aug 23, 2018 at 17:21 Deepak jhaDeepak jha 3085 silver badges19 bronze badges2 Answers
Reset to default 9You could try to add a script to the new site that removes all service workers, if there are any:
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.getRegistrations().then(function(registrations) {
for (let registration of registrations) {
registration.unregister();
}
});
}
</script>
If this is not sufficient in your case, check out self-destroying-sw:
Remove everything about your previous ServiceWorker (registration/uninstallation code, ServiceWorker file)
Create a file with the same name as your previous ServiceWorker and put it in the same place where your previous ServiceWorker was
Put following code into the file:
self.addEventListener('install', function(e) { self.skipWaiting(); }); self.addEventListener('activate', function(e) { self.registration.unregister() .then(function() { return self.clients.matchAll(); }) .then(function(clients) { clients.forEach(client => client.navigate(client.url)) }); });
Deploy your project!
本文标签: javascriptCan39t clear Gatsby static site cacheStack Overflow
版权声明:本文标题:javascript - Can't clear Gatsby static site cache - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741269368a2368984.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论