本文介绍了如何使ServiceWorker在缓存重置/ Shift + F5中生存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个即使服务器处于脱机状态也可以工作的网站 - 我发现这就是适用于。

I want to create a website that can work even when it's server is offline — I found that that's what ServiceWorkers are for.

当我使用服务工作者重新加载页面而没有连接时,它可以正常工作。但是,shift + reload(例如绕过缓存)会解除服务工作者的阻塞,并且无法连接到服务器错误。

When I reload the page with service worker and no connectivity, it works just fine. However, shift+reload (e.g. bypassing cache) disarms service worker and I get "could not connect to server" error.

我的问题是 - 我可以以某种方式阻止转移+从破坏服务工作者重新加载(shift + f5,ctrl + f5等),或者至少使其恢复而不恢复连接?

My question is — can I somehow prevent shift+reload (shift+f5, ctrl+f5 etc) from ruining service worker, or, at least, make it recover afterwards without restoring connectivity?

推荐答案

快速回答



QUICK Answer

理论上(*),您可以使用js插件来检测 Ctrl Shift ...然后阻止强制刷新发生

Theorically (*), you can do it with js plugins which detect the key hit of Ctrl or Shift... then prevent the "force refresh" to happen

...但是这个 Ctrl / Shift 重新加载背后有一个故事。

...but there is a story behind this Ctrl/Shift reload.

(*)免责声明:我还没试过这个

(*) disclaimer: I've not tried this yet

这实际上是Service Worke的规格河并且仅出现在最近的Chrome更改中。对于早期版本的Chrome,Service Worker在强制刷新中没有任何问题。

This is actually a spec of Service Worker. And only present in recent change of Chrome. For the earlier version of Chrome , Service Worker has no any issue surviving a "force refresh".

以及来自

此外,还有很多人(**)建议强制刷新应该始终清除所有类型的缓存。这符合其存在的目的及其规格。

Also, there are many people (**) has suggested that a "force refresh" should always clear out all kind of caches. Which is matched with the purpose of its existent and its spec.

...此外,我们甚至在 ...

...Furthermore, we even got it on the wikipedia...

(* *)我们,服务工作者早期的Web开发人员。

(**) us, web developers in the early stage of service worker.

在我看来,我觉得让力量刷新是可行的它的工作。因为我们几乎所有人都希望浏览器在我们这样做时不使用任何缓存。

这篇关于如何使ServiceWorker在缓存重置/ Shift + F5中生存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 01:39