cache-control

浅谈浏览器的缓存机制

99封情书 提交于 2019-11-30 21:06:24
浏览器的缓存可分为HTTP缓存和离线缓存,下面将分别介绍 HTTP缓存 只有GET请求能被缓存,POST不能被缓存。 Modified Time/ETag/Expires/Cache都是HTTP协议的缓存策略 先来一个例子 当我们第二次访问百度首页,在Chrome的Network面板中打开一个静态文件时会发现响应的status是: 200 OK (from disk cache) ,不是应该返回304 Not Modified吗?如果你知道答案,那就可以忽略本文了。 Cache-Control 简介 w3.org 的定义是:“The Cache-Control general-header field is used to specify directives which MUST be obeyed by all caching mechanisms along the request/response chain.” 这是一个通用首部字段(就是请求报文和响应报文都能用上的字段),用来控制HTTP缓存的行为。 例如: Cache-Control: max-age=3600, public public 意味着这个响应可以被任何人缓存 max-age 则表明了该缓存有效的秒数,允许你的网站被缓存将大大减少下载时间和带宽,同时也提高浏览器的载入速度。 也可以通过设置 no-cache

浅谈浏览器的缓存机制

雨燕双飞 提交于 2019-11-30 21:03:03
浏览器的缓存可分为HTTP缓存和离线缓存,下面将分别介绍 HTTP缓存 只有GET请求能被缓存,POST不能被缓存。 Modified Time/ETag/Expires/Cache都是HTTP协议的缓存策略 先来一个例子 当我们第二次访问百度首页,在Chrome的Network面板中打开一个静态文件时会发现响应的status是: 200 OK (from disk cache) ,不是应该返回304 Not Modified吗?如果你知道答案,那就可以忽略本文了。 Cache-Control 简介 w3.org 的定义是:“The Cache-Control general-header field is used to specify directives which MUST be obeyed by all caching mechanisms along the request/response chain.” 这是一个通用首部字段(就是请求报文和响应报文都能用上的字段),用来控制HTTP缓存的行为。 例如: Cache-Control: max-age=3600, public public 意味着这个响应可以被任何人缓存 max-age 则表明了该缓存有效的秒数,允许你的网站被缓存将大大减少下载时间和带宽,同时也提高浏览器的载入速度。 也可以通过设置 no-cache

HTTP “Expires” header does not work in Chrome

自古美人都是妖i 提交于 2019-11-30 17:28:31
My system is Windows 7 x64, Chrome 20.0.1132.57 m. In my HTTP response header, I have: Cache-Control: public, max-age=1000 Expires: *some date* In IE & FF, the page is cached in local, and when I try to access again by typing the URL and hit enter, no request is send and the page is displayed correctly. But in Chrome, it always send a request to the server with the following header: Cache-Control: max-age=0 I do not want the client send a request to my server and then reply 304. I want to save the round-trip time. Be carefull when you are testing. I noticed that in Chrome version 20 if I hit

Flask static file Cache-Control

旧城冷巷雨未停 提交于 2019-11-30 17:16:20
I'm trying to set a reasonable cache expiry for my JS files while in development. I have the standard setup, where HTML, CSS and JS are living under the static directory. The docs do mention this, but for the life of me I cannot get this to work. I've tried both methods implied, first class MyFlask(flask.Flask): def get_send_file_max_age(self, name): if name.lower().endswith('.js'): return 60 return flask.Flask.get_send_file_max_age(self, name) app = MyFlask(__name__) and app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 60 Both have had no effect, my JS files under /static are still coming back with

Most Efficient Way Of Clearing Cache Using ASP.NET

痴心易碎 提交于 2019-11-30 11:22:09
I am building an ASP.NET/Umbraco powered website which is very custom data driven via entity framework, we are having to cache quite a lot of the data queries (For example searches by keyword) as it's a busy site. But when a user creates a new data entry, I need to clear all the cached queries (Searches etc..) so the new entry is available in the results. So in my create, delete and update methods I am calling the following method: public static void ClearCacheItems() { var enumerator = HttpContext.Current.Cache.GetEnumerator(); while (enumerator.MoveNext()) { HttpContext.Current.Cache.Remove

Right out of the box cache-control header filter?

余生颓废 提交于 2019-11-30 10:10:37
Is there a right of the box cache-control response header filter that will enable me to set those cache headers on my static resources without me having to build my own Filter? It seems like such a common task. Is there a Spring filter ? I am currently using Tomcat 6.0 and using Spring's ShallowEtagHeaderFilter to set etag to my resources but I need to also add the cache-control headers. Use mvc:resources for static files and mvc:interceptors with WebContentInterceptor for non-static files e.g. <!-- cache for one month --> <mvc:resources location="/css/" mapping="/css/**" cache-period="2592000

Proxy cacheing - What about cookies? [closed]

若如初见. 提交于 2019-11-30 08:30:40
I read http://code.google.com/speed/page-speed/docs/caching.html . It says that proxy servers may cache cookies. I need clarification. Let's say I have this header for my files: Cache-Control "max-age=604800, public" Q.1. With this header, will the cookies from a person's computer be cached on the proxy server when a static file is accessed? (Then, would the next person to access the file pick up the other person's cookies?) Now, let's say the cache code went like Cache-Control "max-age=7200, proxy-revalidate" instead. Q.2. What would be the difference as far as cookie cacheing on the proxy

set cache-control to external resources?

耗尽温柔 提交于 2019-11-30 08:20:56
问题 @tools.pingdom.com I get a warning in leverage cache-control because of these resources: http://code.jquery.com/jquery-1.6.2.min.js http://www.google-analytics.com/ga.js http://edge.sharethis.com/images/spinner.gif http://w.sharethis.com/button/buttons.js Which are not in my host. What can I do about this? This is the beginning of my htaccess: # 480 weeks <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|css|swf)$"> Header set Cache-Control "max-age=290304000, public" </FilesMatch> # 1 weeks

How to add headers in nginx only sometimes

陌路散爱 提交于 2019-11-30 07:15:44
I have a nginx proxy to a API server. The API sometimes sets the cache control header. If the API hasnt set the cache control I want nginx to override it. How do I do that? I think I want to do something like this, but it doesnt work. location /api { if ($sent_http_cache_control !~* "max-age=90") { add_header Cache-Control no-store; add_header Cache-Control no-cache; add_header Cache-Control private; } proxy_pass $apiPath; } You cannot use if here, because if , being a part of the rewrite module, is evaluated at a very early stage of the request processing, way before proxy_pass is called and

Which HTTP status codes are cacheable?

ぃ、小莉子 提交于 2019-11-30 04:23:35
问题 As stated in the title, which HTTP status codes are acceptable to cache as a browser? I did a quick search and did not find an authoritative answer. Originally I thought it may only be 200 OK responses, but I couldn't find any evidence to support that thought. 回答1: Short answer According to the RFC 7231, the current reference for content and semantics of the HTTP/1.1 protocol, the following HTTP status codes are defined as cacheable unless otherwise indicated by the method definition or