Post / Redirect / Get忽略高速缓存控制的全页面重新加载 [英] Full page reload on Post/Redirect/Get ignoring cache control

查看:167
本文介绍了Post / Redirect / Get忽略高速缓存控制的全页面重新加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个加载大量图像,CSS和JavaScript的页面。我已经添加了一个远期未来的Expires头文件,并将Cache-Control设置为公开于这些外部依赖项,以便它们应该被缓存。但是每次我做一个Post / Redirect / Get chrome都会尝试重新加载它们。这种行为与重新加载页面非常相似。我已经添加了ETags并处理了If-None-Match头,这有点帮助,但它仍然会产生太多无用的请求。



我如何告诉chrome和safari从缓存中获取文件?

  chrome NOK 
safari NOK
firefox OK
ie OK

另请参阅在Google支持论坛上完整页面重新加载Post / Redirect /获取忽略缓存控制权



澄清:我不希望浏览器请求 image1.png c $ c>两次。它应该被缓存。

  200 GET page1.html 
200 GET image1.png(Cache-Control:public, (如果不匹配)

示例:

我已经创建了一个简单的例子来说明问题。



http://crydust.be/lab/prg/



标题:

我用图像发送的标题是:

  HTTP / 1.1 200 OK 
日期:星期五,2010年6月18日星期五11:30:22 GMT
服务器:Apache
Cache-Control:public,max-age = 86400
过期时间:2010年6月19日星期六11:30: 24 GMT
Etag:123
Content-Length:866
Content-Type:image / png

应该让它缓存24小时。没有Vary:*或类似的东西。



更新:
此行为现在也出现在iOS iOS上的Safari Mobile 4.页面加载速度的巨大回落。


更新:
在webkit bugzilla中存在有关此问题的错误报告。
错误38690 - 提交导致服务器重定向的POST会导致所有缓存项目重新下载



更新:
问题在iOS 4.0.1中仍然存在



更新:
问题在iOS 4.1中仍然存在
更新:

这个问题在iOS 4.2上仍然存在

更新:
问题在iOS 4.2.1上仍然存在
以及从版本6到版本9的Chrome。



更新:
在Chromium项目中存在有关此问题的错误报告。 (你可以用它来给你看看)
Issue 68621 :发布/重定向/忽略缓存指令



更新:
从版本6开始, 10.
现在是一个9个月的bug。

更新:
问题在2011年-03-21 19:33:07太平洋标准时间。这反映在chrome 12(canary)的行为中。

解决方案

当你在Chrome,Safari或IE8中刷新F5 /即使它们已被缓存,也会再次请求GET资源。



如果您使用开发工具或Fiddler观看请求/响应,您会看到服务器以HTTP 304状态响应并且没有内容。这告诉浏览器他们不需要再次下载它,并且他们可以继续使用缓存。



在Chrome的开发工具'资源标签文件刷新像这样将有一个延迟时间,但下载时间为0毫秒。



如果您通过退出重新加载页面并返回,您会发现这些缓存的文件不会再次检索并且服务器没有被检查。



这种对于GET静态资源的F5 / refresh的行为是正确的 - 它是FX和IE6的错误。它也有助于大多数用户不知道的令人困惑的CTRL + F5命令。



无法缓存POST或返回临时HTTP重定向的页面:



POST会更改数据,并且应该在再次发送之前始终提示,并且其结果永远不会被缓存。

重定向在HTTP缓存中处于低级别。真的,它告诉浏览器从其他地方获取资源,并且可以缓存它没有缓存重定向并需要再次检查。

您应该可以缓存301永久重定向,但不应缓存302或303个临时重定向根据HTTP规范


I have a page that loads a lot of images, css and javascript. I've added a far future Expires header and set Cache-Control to public on these external dependencies so they should be cached. But every time I do a Post/Redirect/Get chrome tries to load these again. This behavior is very similar to reloading the page. I've added ETags and handle the If-None-Match header which helps a bit, but it still generates too many useless requests.

How do I tell chrome and safari to get the files from cache?

chrome   NOK
safari   NOK
firefox  OK
ie       OK

Also see Full page reload on Post/Redirect/Get ignoring cache control on the google support forum.

Clarification:

I don't want the browser to request image1.png twice. It should be cached.

200 GET  page1.html
200 GET  image1.png (Cache-Control: public, Expires and ETag)
302 POST action.asp (form submitted from page1.html, redirects)
200 GET  page2.html
304 GET  image1.png (If-None-Match)

Example:

I've created a simple example to illustrate the problem.

http://crydust.be/lab/prg/

Headers:

The headers I send with the image are:

HTTP/1.1 200 OK
Date: Fri, 18 Jun 2010 11:30:22 GMT
Server: Apache
Cache-Control: public, max-age=86400
Expires: Sat, 19 Jun 2010 11:30:24 GMT
Etag: "123"
Content-Length: 866
Content-Type: image/png

Which should make it cached for 24 hours. There is no Vary: * or anything like that.

Update: This behavior is now also present in Safari Mobile on iOS 4. A horible regression in page-load speed.

Update: There is a bugreport about this issue in the webkit bugzilla. Bug 38690 - Submitting a POST that leads to a server redirect causes all cached items to redownload

Update: The problem persists on iOS 4.0.1

Update: The problem persists on iOS 4.1

Update: The problem persists on iOS 4.2

Update: The problem persists on iOS 4.2.1 and in Chrome from version 6 till 9.

Update: There is a bugreport about this issue in the Chromium project. (you can star it to show you care) Issue 68621: Post/Redirect/Get ignoring cache instructions

Update: The problem persists on Chrome from version 6 till 10. It is now a 9 months old bug.

Update: The problem is fixed as of 2011-03-21 19:33:07 PST. This is reflected in the behavior of chrome 12 (canary).

解决方案

When you F5/refresh in Chrome, Safari or IE8 all the GET resources are requested again, even if they've been cached.

If you watch the request/response with the dev tools or Fiddler you'll see that the server responds with an HTTP 304 status and no content. This tells the browser that they don't need to download it again and that they can continue to use the cache.

In Chrome's dev tools' Resource tab files refreshed like that will have a latency time, but a download time of 0ms.

If you reload the page by leaving and returning you'll find that these cached files are not retrieved again and the server is not checked.

This behaviour of F5/refresh for GET static resource is correct - it's FX and IE6 that are doing it wrong. It also helps with the confusing CTRL+F5 command that most users don't know about.

You can't cache POST or pages that return a temporary HTTP redirect:

POST changes data and should always prompt before being sent again, and its results are never cached.

Redirects are handled at a low level in the HTTP stuff - below caching. Really it tells the browser to get the resource from somewhere else and while it can cache that it hasn't cached the redirect and needs to check again.

You should be able to cache a 301 permanent redirect, but a 302 or 303 temporary redirects shouldn't be cached according to the HTTP spec.

这篇关于Post / Redirect / Get忽略高速缓存控制的全页面重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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