HTML 5 Cache Manifest Vs. Etags,Expires或缓存控制标题 [英] HTML 5 Cache Manifest Vs. Etags, Expires or cache-control header

查看:122
本文介绍了HTML 5 Cache Manifest Vs. Etags,Expires或缓存控制标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释HTML 5的缓存清单与使用其他文件头技术告诉浏览器缓存文件有何不同?

解决方案

我觉得很奇怪,你回答了一个问题的答案,评论回答了你自己但我认为你在这个话题中绝对垄断的近两年就足够了。 ;)



HTML5缓存清单与传统HTTP头文件之间的主要区别:


  • 获取您需要在浏览器中支持的缓存清单

  • 代表您在浏览器中也需要支持的HTTP标头,但它更通用

  • 通过缓存清单,您可以更好地控制缓存

  • 您的网站或Web应用程序可以在离线状态下正常工作可以有两个版本的每个资源 - 用于离线和在线使用



最后一点非常方便,可以轻松地将部分网站,需要与例如。



有关支持,请参阅支持桌面和移动浏览器中的离线Web应用程序的兼容性表格。毫不奇怪,IE总有一些问题,目前Opera Mini不支持它,所以我建议如果你使用缓存清单,那么也可以使用传统的HTTP头文件(包括HTTP / 1.1 Cache-控制和HTTP / 1.0过期 - 请参阅 RFC 2616 sec。14.9。 3 )。



您可以更好地控制JavaScript中的整个缓存过程,例如。您可以使用window.applicationCache.swapCache()方法强制更新网站的缓存版本,而无需手动重新加载页面。 HTML5 Rocks (以下链接)解释了如何将用户更新到最新版本请注意,您需要为您的缓存清单提供正确的HTTP标头,特别是与缓存相关的Content-Type和标头。您的浏览器知道它是一个缓存清单,并且应该始终检查它的新版本。例如,Github如何为GitHub页面提供缓存清单:

  Content-Type:text / cache-manifest 
Cache-Control:max-age = 0
Expires:[CURRENT TIME]

CURRENT TIME]是当前格林威治标准时间的正确格式(请参阅 RFC 2616 sec。3.3 )。

以下是一些可以帮助您开始使用的资源:



另请参阅我最近对这些相关问题的回答:


Can someone explain to me how HTML 5's cache manifest differs from using other file header techniques for telling the browser to cache the file?

解决方案

I feel strange posting an answer to a question that you have asked, commented and answered yourself but I think that nearly two years of your absolute monopoly in this topic is enough. ;)

The main differences between the HTML5 cache manifest vs. the traditional HTTP headers:

  • for the cache manifest you need support in the browser
  • for the HTTP headers you also need support in the browser of course but it's more universal
  • you have more control over the caching with cache manifest
  • your website or Web app can work correctly offline with no connection at all
  • you can have two version of every resource - for offline and online usage

The last point is very handy and lets you easily swap parts of your website that need connection with eg. placeholders containing optional comments that the user doesn't get full functionality without the connection or whatever you want.

For the support see the Compatibility table for support of offline web applications in desktop and mobile browsers. Not surprisingly IE has some problems like always, currently Opera Mini doesn't support it, so I would suggest that if you use cache manifests then to also use the traditional HTTP headers (both HTTP/1.1 Cache-Control and HTTP/1.0 Expires - see RFC 2616 sec. 14.9.3).

You have more control over the whole caching process in your JavaScript, eg. you can use the window.applicationCache.swapCache() method to force an update of the cached version of your website without the need for manually reloading the page. There are some nice code examples on HTML5 Rocks (links below) explaining how to update users to the newest version of your website or Web application.

Keep in mind that you need to serve your cache manifest with correct HTTP headers, specifically the Content-Type and headers related to caching so that your browser knows that it's a cache manifest and that it should always be checked for new versions. This is for example how Github serves cache manifests for GitHub Pages:

Content-Type: text/cache-manifest
Cache-Control: max-age=0
Expires: [CURRENT TIME]

where [CURRENT TIME] is the current GMT time in the correct format (see RFC 2616 sec. 3.3).

Here are some resources that will get you started:

See also my recent answers to those related questions:

这篇关于HTML 5 Cache Manifest Vs. Etags,Expires或缓存控制标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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