检查浏览器是否禁用离线应用程序缓存 [英] Check if offline application cache disabled by browser
问题描述
它显示,通过检查缓存的状态可以检测到这个状态,这将返回0 UNCACHED
当没有缓存...但我不知道这是否意味着没有缓存尚,或没有缓存保证(因为应该有,有什么不对)。 官方定义不是很有用:
$ $ $ $ $ $ $ $ $ $ $ $ $ UNCACHED(数值0)
ApplicationCache对象的缓存主机没有与应用程序相关联
缓存在这个时候。
实际上,放弃 cache.status == 0
似乎至少在Firefox上正常工作。我做对了,还是有更好的办法?如果有人可以挖掘一个状态图,则可以获得额外的分数。
更新:如果用户从来没有去过,它也会返回0 / UNCACHED那个页面之前。加油!
监听错误
C> applicationCache 。当这种情况发生时, applicationCache.status === applicationCache.UNCACHED
, 中的一个原因是缓存被禁用。给用户的消息可能会提示缓存已关闭。
So I've got an application that stores offline data using an ApplicationCache. Long story short, it's silently dying for users who don't have offline data enabled, most commonly because they've got history turned off or are using private browsing, and I'd like to catch this and give the user a clear error.
It appears that this can be detected by checking the cache's state, which will return 0 UNCACHED
when there is no cache... but I'm not sure if that means that there is no cache yet, or that there's no cache guaranteed (and because there should be, something's wrong). The official definition is less than useful:
UNCACHED (numeric value 0)
The ApplicationCache object's cache host is not associated with an application
cache at this time.
In practice, though, aborting on cache.status==0
seems to work fine at least on Firefox. Am I doing it right, or is there a better way? Extra points if somebody can dig up a state diagram.
Update: Nope, it also returns 0/UNCACHED if the user has never been to that page before. Gar!
Listen for the error
event on applicationCache
. When this fires and applicationCache.status===applicationCache.UNCACHED
, one reason among many is that caching is disabled. The message to the user may suggest that caching is turned off.
这篇关于检查浏览器是否禁用离线应用程序缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!