在HTML5离线应用中需要swapCache()吗? [英] Is swapCache() required in HTML5 offline apps?

查看:111
本文介绍了在HTML5离线应用中需要swapCache()吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我没有实现任何 updateready 事件处理程序并且不调用 swapCache(),那么意味着浏览器将始终使用应用程序的第一个(最旧的)下载版本?

If I don't implement any updateready event handler and don't call swapCache(), does that mean that the browser will always use the first (oldest) downloaded version of the application?

如果不是,那么为什么 swapCache()<需要/ code>方法?

If no, then why is the swapCache() method needed?

推荐答案

Swapcache确保从新的资源中获取对缓存资源的后续调用缓存。
在swapcache之后的后续含义。
要查看此操作,请尝试在updateready事件中的
swapcache调用之后动态设置img的src属性(以便浏览器在特定的
时间加载它)。确保此图像尚未加载到页面的其他位置,因为
会扭曲此测试。
现在更改映像并更改清单文件(强制重新加载缓存的文件)。
在您的浏览器中重新加载页面。
您现在应该在渲染页面中看到图像的新版本。
现在注释掉对swapcache的调用。
对清单文件进行更改并重新加载页面,从而重新加载所有资源。
再次刷新页面(以确保您拥有新缓存中的版本)。
现在再次更改图像并更改清单。
再次重新加载页面:现在您看到旧版本的图像。
在最后一种情况下,浏览器已完成在缓存中加载新版本,但由于未调用
swapcache,因此仍然从旧缓存中获取图像。

Swapcache makes sure that "subsequent" calls to cached resources are taken from the new cache. Subsequent meaning after swapcache. To see this in action try setting the src property of an img dynamically after the swapcache call in the updateready event (so that the browser loads it at that particular time). Make sure this image is not already loaded elsewhere in the page since that will distort this test. Now change the image and change the manifest files (to force reloading the cached files). Reload the page in your browser. You should now see the new version of the image in your rendered page. Now comment out the call to swapcache. Make a change to the manifest file and reload the page and thus all resources. Refresh the page again (to make sure you have a version from the new cache). Now change the image again and change the manifest. Again reload the page: now you see the old version of the image. In the last case, the browser finished loading the new versions in cache, but since swapcache was not called, the image was still taken from the old cache.

如果您没有在页面中动态加载资源,则swapcache无效。

If you do not do any dynamic loading of resources in your page, the swapcache has no effect.

特别是,如果您重新加载页面中的updateready事件处理程序调用swapcache
首先没有效果,因为重新加载页面将会从新缓存中获取它。

In particular, if you reload the page in the updateready event handler calling swapcache first has no effect since reloading the page will get it from the new cache anyway.

这篇关于在HTML5离线应用中需要swapCache()吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆