Google App Engine不会生成304,而是始终生成200 [英] Google App Engine not generating 304, instead generating 200 always

查看:81
本文介绍了Google App Engine不会生成304,而是始终生成200的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google App引擎始终为网址/test.js 生成200,并且 test.js不是静态资源,而是用于动态生成内容的url模式.该内容将在N小时后过期,并且将生成一个新内容.

Google App engine always generates 200 for the url /test.js and test.js is not a static resource, but a url pattern for dynamically generated content. The content will expire after N hours and a fresh content will be generated.

我尝试使用Last-Modified,ETag和Cache-Control.似乎没有任何作用.

I've tried with Last-Modified, ETag and Cache-Control. None seems to work.


Request URL:http://localhost:8081/test.js
Request Method:GET
Status Code: 200 OK
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Host:localhost:8081
If-Modified-Since:Fri, 18 Oct 2013 14:10:39 GMT
If-None-Match:"1B2M2Y8AsgTpgAmY7PhCfg"
Referer:http://localhost:8080/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36

响应标题



cache-control:public, max-age=360000
Content-Length:2
content-type:application/script; charset=utf-8
Date:Fri, 18 Oct 2013 14:10:40 GMT
etag:"1B2M2Y8AsgTpgAmY7PhCfg"
expires:Tue, 22 Oct 2013 18:10:40 GMT
last-modified:Fri, 18 Oct 2013 14:10:40 GMT
Server:Development/2.0

推荐答案

有关HTTP状态,请参见此: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

Refer to this for HTTP status: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

200只是正确的HTTP OK状态,它对资源是否静态没有任何解释. (尝试使用诸如Facebook之类的任何动态网页),您会注意到它是200.响应为200完全正常

200 is just the correct HTTP OK status, that doesn't have any interpretation on whether the resource is static or not. (Try any dynamic web page out there like e.g. facebook) and you will notice it's 200. Having a response of 200 is perfectly normal

对于304,它是未修改的"-如w3中所述:"304响应必须不包含消息正文".这不是你想要的.

for 304 it's "Not Modified" - As mentioned in w3 "The 304 response MUST NOT contain a message-body". This is not what you want.

在您的情况下,您应该考虑为这些http标头设置正确的到期时间(在程序代码中进行设置),以便浏览器始终在到期时间之后(例如1小时后)请求新的内容副本):

In your case your concern should be to set the correct expiry time for these http header (do it within your program code), so that the browser always request for a fresh copy of content after the expiry time (e.g. after 1 hour):

cache-control:public, max-age=3600
expires:Tue, 20 Oct 2013 18:10:40 GMT

这篇关于Google App Engine不会生成304,而是始终生成200的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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