使用哪一个:过期标头,最后修改的标头或ETag [英] Which one to use : Expire Header, Last Modified Header or ETags

查看:64
本文介绍了使用哪一个:过期标头,最后修改的标头或ETag的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Apache上运行PHP,并且对如何实现服务器端缓存感到困惑,以使站点加载速度更快.

I am running PHP on Apache, and am confused about how to implement server-side caching, in order to make the site load faster.

Expires Last-Modified ETag 标头之间有什么区别?在哪种情况下应使用哪一个?/p>

What is the difference between the Expires, Last-Modified and ETag headers, and which one should be used in what situation?

推荐答案

您可以结合使用 Expires 标头,但不考虑其他两个标头.代理和浏览器缓存普遍支持它.

You can use the Expires header in conjunction but regardless of the other two. It's universally supported by proxies and browser caches.

ETag Last-Modified 戳之间的区别更多是语义上的.ETag对客户端而言是不透明的.通常是校验和.客户端可以解释Last-Modified标头.据了解,最后修改的时间戳是线性工作的.

The difference between ETag and Last-Modified stamps is more semantic. ETags are opaque to clients. It's usually a checksum. Whereas a Last-Modified header can be interpreted by clients. It's understood that the last modified timestamp works linearly.

如果浏览器使用 If-Unmodified-Since 请求资源,则过去的各种时间戳都可以满足这种条件.如果您的页面经常更改,则使用Last-Modified时间戳可能会有所帮助.

If a browser requests a resource with If-Unmodified-Since, then a wide range of timestamps in the past can match such a condition. If your pages change frequently then a Last-Modified timestamp might be advantageous.

另一方面,ETag方法导致客户端为每个资源节省最后一个指纹.(我不确定浏览器缓存是否记住多个ETag).根据请求,仅列出一个或几个可能的 If-None-Match 令牌.这可能意味着更多的错过.另外,您必须比较多个校验和,而使用Last-Modified时间戳,则可以进行算术比较.

The ETag approach, on the other hand, leads to clients that save one last fingerprint per resource. (I'm not sure if browser caches remember multiple ETags). On requests, only one or a few possible If-None-Match tokens are listed. This might mean more misses. Also, you have to compare multiple checksums, whereas with a Last-Modified timestamp you could have an arithmetic comparison.

ETags的真正优势在于您可以可靠地比较指纹.Last-Modified时间戳更加模糊,因为它们无法验证实际页面内容是否已更改.

The real advantage of ETags is that you can reliably compare fingerprints. The Last-Modified timestamps are a bit more vague, as they don't verify if the actual page content changed.

另请参阅:

这篇关于使用哪一个:过期标头,最后修改的标头或ETag的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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