• <bdo id='DyPKU'></bdo><ul id='DyPKU'></ul>

    <small id='DyPKU'></small><noframes id='DyPKU'>

    <legend id='DyPKU'><style id='DyPKU'><dir id='DyPKU'><q id='DyPKU'></q></dir></style></legend>
    1. <tfoot id='DyPKU'></tfoot>
      <i id='DyPKU'><tr id='DyPKU'><dt id='DyPKU'><q id='DyPKU'><span id='DyPKU'><b id='DyPKU'><form id='DyPKU'><ins id='DyPKU'></ins><ul id='DyPKU'></ul><sub id='DyPKU'></sub></form><legend id='DyPKU'></legend><bdo id='DyPKU'><pre id='DyPKU'><center id='DyPKU'></center></pre></bdo></b><th id='DyPKU'></th></span></q></dt></tr></i><div id='DyPKU'><tfoot id='DyPKU'></tfoot><dl id='DyPKU'><fieldset id='DyPKU'></fieldset></dl></div>

      HTTP 304 Not Modified-responses 是否应该包含缓存控制标头?

      Should HTTP 304 Not Modified-responses contain cache-control headers?(HTTP 304 Not Modified-responses 是否应该包含缓存控制标头?)
        1. <i id='MNXoD'><tr id='MNXoD'><dt id='MNXoD'><q id='MNXoD'><span id='MNXoD'><b id='MNXoD'><form id='MNXoD'><ins id='MNXoD'></ins><ul id='MNXoD'></ul><sub id='MNXoD'></sub></form><legend id='MNXoD'></legend><bdo id='MNXoD'><pre id='MNXoD'><center id='MNXoD'></center></pre></bdo></b><th id='MNXoD'></th></span></q></dt></tr></i><div id='MNXoD'><tfoot id='MNXoD'></tfoot><dl id='MNXoD'><fieldset id='MNXoD'></fieldset></dl></div>
            <bdo id='MNXoD'></bdo><ul id='MNXoD'></ul>
              <tbody id='MNXoD'></tbody>
          • <small id='MNXoD'></small><noframes id='MNXoD'>

            <tfoot id='MNXoD'></tfoot>
            <legend id='MNXoD'><style id='MNXoD'><dir id='MNXoD'><q id='MNXoD'></q></dir></style></legend>

                本文介绍了HTTP 304 Not Modified-responses 是否应该包含缓存控制标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我试图理解这一点,并搜索了类似的问题,但我仍然没有 100% 了解它应该如何工作.

                I've tried to understand this, and searched SO for similar questions, but I still don't have a 100% understanding on how this is supposed to work.

                我在请求图像资源时收到此响应:

                I get this response on a request for an image resource:

                Response Headers
                    Server  Apache-Coyote/1.1
                    Date    Mon, 19 Oct 2009 09:04:04 GMT
                    Expires Mon, 19 Oct 2009 09:06:05 GMT
                    Cache-Control   public, max-age=120
                    Etag    image_a70703fb393a60b6da346c112715a0abd54a3236
                    Content-Disposition inline;filename="binary-216-420"
                    Content-Type    image/jpg;charset=UTF-8
                    Content-Length  4719
                

                所需的行为是客户端应将此缓存 120 秒,然后再次从服务器请求它.在 120 秒内,没有请求发送到服务器.

                The desired behavior is that the client should cache this for 120 seconds, then request it from the server again. Within the 120 seconds, no request is sent to the server.

                然后,120 秒后,发送请求并收到 304 响应:

                Then, after 120 seconds, a request is sent and a 304 response is received:

                Response Headers
                    Server  Apache-Coyote/1.1
                    Date    Mon, 19 Oct 2009 09:06:13 GMT
                
                Request Headers
                    Host    localhost:8080
                    User-Agent  Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3
                    Accept  image/png,image/*;q=0.8,*/*;q=0.5
                    Accept-Language en-us,no;q=0.8,sq;q=0.7,en;q=0.5,sv;q=0.3,nn;q=0.2
                    Accept-Encoding gzip,deflate
                    Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
                    Keep-Alive  300
                    Connection  keep-alive
                    Referer http://localhost:8080/cms/site/0/en/home
                    Cookie  JSESSIONID=768ABBE1A3BFABE3B535900233330650; versionsCssDisplayState=block; iceInfo=iceOn:false,activePortletKey:,icePagePanelX:1722,icePagePanelY:3
                    If-None-Match   image_a70703fb393a60b6da346c112715a0abd54a3236
                

                到目前为止,一切顺利.但是,在下一个请求(大约 120 秒)时,我会认为资源应该被缓存 120 秒.另一方面,我在浏览器 (Firefox) 中看到的是,它从此时开始总是请求资源并接收 304 响应.

                So far, all well. But then, on the next request (whithin 120 seconds) i would have thought that the resource should be cached for 120 new seconds. What i see in the browser (Firefox) on the other hand, is that it from this point on always request the resource and receives the 304-response.

                我应该在 304 响应中附加缓存控制标头吗?从我在规范中看到的内容来看,似乎应该省略缓存控制设置,并且缓存应该自动将其缓存 120 秒?

                Am I supposed to attach the cache-control headers in the 304-response? From what i can read in the spec, it seems like the cache-control settings should be omitted, and that the cache should cache it for 120 new seconds automatically?

                推荐答案

                理论上你不应该为 304 发送 Cache-Control —— 接收者应该继续使用它从原始接收到的缓存指令200. 但是,正如您所发现的,实际上,如果您不继续发送 Cache-Control,浏览器将忽略您最初发送的缓存指令,并恢复到它们自己的默认启发式.

                In theory you shouldn't have to send Cache-Control for a 304 -- the recipient should just continue to use the cache directives that it received from the original 200. However, as you've found, in practice if you don't keep sending Cache-Control, browsers will ignore the cache directives that you sent originally, and revert to their own default heuristics.

                因此,在实践中,您应该在 304 中包含与 200 相同的 Cache-Control.规范仅要求您在 304 中发送它,如果它与您之前发送的不同(请参阅 10.3.5 304 未修改)——但它肯定没有相同的时候禁止你重复.

                So in practice, you should include the same Cache-Control with a 304 that you would with a 200. The spec only mandates that you send it for a 304 if it's different than what you sent previously (see 10.3.5 304 Not Modified) -- but it certainly doesn't forbid you from repeating it when it's the same.

                并专门回应另一个答案(结构)中的错误观点:

                And to respond specifically to the wrong-headed points from the other answer (Structure's):

                1. 确实希望中间缓存来缓存响应(即更新资源的缓存条目).它们将适当地响应来自客户端的 200 或 304 请求,具体取决于客户端是否包含像 If-Modified-Since 这样的条件标头.

                1. You do want intermediary caches to cache the response (that is, update their cache entry for the resource). They will respond appropriately to requests from clients with a 200 or a 304, depending on whether the client included a conditional header like If-Modified-Since.

                120 秒的 ttl 会被 304 刷新(因此同一个客户端至少在 120 秒内不应再次请求同一个资源).而客户端,只要他们仍然有缓存的内容,继续对资源发出有条件的请求,您可以继续使用 304 响应.

                The 120-second ttl will be refreshed by the 304 (so the same client shouldn't make another request for the same resource for at least another 120 seconds). And clients, as long as they've still got the content cached, will continue to make conditional requests for the resource, which you can continue to respond to with a 304.

                这篇关于HTTP 304 Not Modified-responses 是否应该包含缓存控制标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                quot;Status Code:200 OK (from ServiceWorker)quot; in Chrome Network DevTools?(“状态码:200 OK(来自 ServiceWorker)在 Chrome 网络开发工具中?)
                How to set a header for a HTTP GET request, and trigger file download?(如何为 HTTP GET 请求设置标头并触发文件下载?)
                Adding custom HTTP headers using JavaScript(使用 JavaScript 添加自定义 HTTP 标头)
                What is quot;X-Content-Type-Options=nosniffquot;?(什么是“X-Content-Type-Options=nosniff?)
                SmtpJs API not working! is there any way to send emails using SMTP server with JavaScript or JQuery(SmtpJs API 不工作!有没有办法使用带有 JavaScript 或 JQuery 的 SMTP 服务器发送电子邮件)
                Can I send email using javascript(我可以使用 javascript 发送电子邮件吗)
                  <tbody id='zgx94'></tbody>

                <tfoot id='zgx94'></tfoot>
                  <i id='zgx94'><tr id='zgx94'><dt id='zgx94'><q id='zgx94'><span id='zgx94'><b id='zgx94'><form id='zgx94'><ins id='zgx94'></ins><ul id='zgx94'></ul><sub id='zgx94'></sub></form><legend id='zgx94'></legend><bdo id='zgx94'><pre id='zgx94'><center id='zgx94'></center></pre></bdo></b><th id='zgx94'></th></span></q></dt></tr></i><div id='zgx94'><tfoot id='zgx94'></tfoot><dl id='zgx94'><fieldset id='zgx94'></fieldset></dl></div>
                1. <small id='zgx94'></small><noframes id='zgx94'>

                  • <bdo id='zgx94'></bdo><ul id='zgx94'></ul>

                    1. <legend id='zgx94'><style id='zgx94'><dir id='zgx94'><q id='zgx94'></q></dir></style></legend>