如果过期和/或没有缓存标头未设置,Google Chrome会缓存资源多长时间? [英] How long does Google Chrome cache a resource if expires and/or no-cache headers are not set?

查看:399
本文介绍了如果过期和/或没有缓存标头未设置,Google Chrome会缓存资源多长时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在Chrome上缓存Glassfish服务器上的资源时遇到问题。不会发送expires和no-cache头文件,并且Chrome会缓存资源(大约4 MB SWF文件) - 尽管存在Last-Modified头文件。



有时候Chrome会得到一个304代码,有时候它只是做一个200(来自缓存)。我知道304 - Chrome可能会检查最新的最新修改日期和缓存版本来决定。但有些时候它会执行200(来自缓存),它不会返回任何标题信息,并显示Chrome只是假设文件没有被修改而不是检查。



Google自己的网站状态以下内容:


HTTP / S支持浏览器对静态资源的本地缓存。一些
的最新浏览器(例如IE 7,Chrome)使用启发式方法来决定
缓存所有没有显式缓存
标题的资源。


但这并不能提供明确的答案。这种启发式发布在哪里?我意识到可能没有固定的答案(比如30天),但是一些通用的指导方针会很有用。此外,如果设置了Last-Modified,我不明白为什么Chrome不会首先检查这个问题。 解决方案

DEFAULT_CACHE_TIME = 300



我通过搜索http://code.google.com/p/chromium/source/search?q=DEFAULT_CACHE_TIME&origq = DEFAULT_CACHE_TIME& btnG =搜索+中继线DEFAULT_CACHE_TIME。



有一个名为chromeextensionsdocs.py的文件,其中包含DEFAULT_CACHE_TIME。

I / i>这是基于 http://code.google.com/中给出的示例的秒数appengine / docs / python / memcache / overview.html

在chromeextensionsdocs.py中,DEFAULT_CACHE_TIME作为 memcache.add $ b

我不完全确定这是否是正确的值,但看起来很可能是将这些部分放在一起。


We have been having a problem with Chrome caching a resource on our Glassfish server. The expires and no-cache headers are not being sent and the resource (an approximately 4 MB SWF file) is being cached by Chrome -- despite the presence of the Last-Modified header.

Sometimes Chrome will get a 304 code, and other times it simply does a 200 (from cache). I understand the 304 -- Chrome is likely checking the most recent Last-Modified date with the cached version to decide. But other times it does the 200 (from cache), which does not return any header information and appears that Chrome is simply assuming the file hasn't been modified instead of checking.

Google's own site states the following:

HTTP/S supports local caching of static resources by the browser. Some of the newest browsers (e.g. IE 7, Chrome) use a heuristic to decide how long to cache all resources that don't have explicit caching headers.

But this does not provide a definitive answer. Is this heuristic published anywhere? I realize there may not be a fixed answer (like 30 days), but some general guidelines would be useful. Furthermore, if Last-Modified is being set, I don't understand why Chrome isn't bothering to check that first.

解决方案

DEFAULT_CACHE_TIME = 300

I found the above by searching at http://code.google.com/p/chromium/source/search?q=DEFAULT_CACHE_TIME&origq=DEFAULT_CACHE_TIME&btnG=Search+Trunk for "DEFAULT_CACHE_TIME".

There's a file called "chromeextensionsdocs.py" that contains the DEFAULT_CACHE_TIME.

I believe this is seconds based on the example given at http://code.google.com/appengine/docs/python/memcache/overview.html
In "chromeextensionsdocs.py", the DEFAULT_CACHE_TIME is sent as the last param in memcache.add

I'm not totally sure if this is the right value or not but seems likely that it is when putting the pieces together.

这篇关于如果过期和/或没有缓存标头未设置,Google Chrome会缓存资源多长时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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