简体   繁体   English

完全强制SPA刷新,而忽略缓存,服务人员等

[英]Completely forcing a SPA refresh, ignoring cache, service workers and so on

I have a website built with Vue (SPA). 我有一个使用Vue(SPA)构建的网站。 I was playing with service workers and it seems that I completely screwed something, because now I can't see anything but a blank website in Safari on my iPhone. 我当时正在和服务人员一起玩,看来我完全搞砸了,因为现在除了iPhone上的Safari浏览器中的空白网站之外,我什么都看不到。

I debugged the problem by plugging my phone into my Mac and using Safari's inspector tool see what's going on. 我通过将手机插入Mac并使用Safari的检查器工具来查看问题的发生,从而调试了问题。 It seems that a service worker is providing an old index.html file, which then tries to pull an old .js file (which doesn't exist anymore on the server). 似乎服务人员正在提供旧的index.html文件,然后尝试拉出旧的.js文件(服务器上已不存在)。 Because the server is returning a text/plain reply (a 404 page), safari on my phone is halting everything, because the content type of that 404 page doesn't match the expected content type of a .js file. 由于服务器返回的是文本/纯文本答复(404页面),因此手机上的Safari浏览器将停止所有操作,因为该404页面的内容类型与.js文件的预期内容类型不匹配。

The website still works fine on other devices, so at this point I'm not 100% sure if I'm the one to blame, or is it Safari's fault. 该网站在其他设备上仍然可以正常运行,因此,目前还不能100%肯定是我该当责怪的,还是Safari的错。

Either way, I want to, somehow, force a complete cache removal (including service workers). 无论哪种方式,我都想以某种方式强制完全删除缓存(包括服务工作者)。 Is that possible? 那可能吗? If not, how can I fix this problem? 如果没有,如何解决此问题?

Not knowing the capabilities of remote debugging on your phone assuming you can inject js to run on it using the dev tools you could unregister the service worker using something like: 假设您可以使用开发工具注入js在其上运行,因此不知道手机上的远程调试功能,您可以使用以下方法注销服务工作者:

 navigator.serviceWorker.getRegistrations().then(function(registrations) { for(let registration of registrations) { registration.unregister() } }) 

Please note credits go to: https://stackoverflow.com/a/33705250/966530 请注意学分,请访问: https : //stackoverflow.com/a/33705250/966530

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM