YSlow 报告“无过期日期”和“不可高速缓存”

发布于 2024-10-28 19:36:54 字数 141 浏览 3 评论 0原文

我有一个网页:http://uranussup.info。我进行了 yslow 测试。有很多请求 (20),并且显示“内容不可缓存”和“无过期日期”。我该如何修复它?

I have a wep page: http://uranussup.info. I ran a yslow test. There are a lot of requests (20) and it says "Content is not cacheable" and "No expire date." How can I fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦断已成空 2024-11-04 19:36:54

简短版本

您需要配置您的服务器,以便它使用不同的 HTTP 标头 为您的网站内容提供服务。

长版

来自 Yahoo! 加快网站速度的最佳实践

添加过期或缓存控制标头

该规则有两个方面:

  • 对于静态组件:通过设置 far 来实现“永不过期”策略
    未来的 Expires 标头
  • 对于动态组件:使用适当的 Cache-Control 标头
    有条件地帮助浏览器
    请求

网页设计越来越丰富
更丰富,这意味着更多的脚本,
样式表、图像和 Flash
页。第一次来访您的
页面可能要进行多次HTTP
请求,但通过使用 Expires
你制作这些组件的标题
可缓存。这样可以避免不必要的
后续页面的 HTTP 请求
意见。过期标头最常见
与图像一起使用,但它们应该是
用于所有组件,包括
脚本、样式表和 Flash
组件。

浏览器(和代理)使用缓存来
减少 HTTP 的数量和大小
请求,使网页加载
快点。 Web 服务器使用 Expires
HTTP 响应中的 header 来告诉
客户端组件可以有多长
缓存。这是遥远的未来
标头,告诉浏览器这是
响应直到四月才会过时
2010 年 15 日。

过期:2010 年 4 月 15 日星期四 20:00:00 GMT

如果您的服务器是 Apache,请使用
ExpiresDefault 指令设置
到期日期相对于
当前日期。这个例子的
ExpiresDefault 指令设置
到期日为 10 年后
请求的时间。

ExpiresDefault“访问权限加 10 年”

请记住,如果您使用遥远的未来
标题过期,您必须更改
组件的文件名
组件变化。在雅虎!我们经常
使此步骤成为构建的一部分
流程:嵌入版本号
在组件的文件名中,对于
例如,yahoo_2.0.6.js。

使用远期的 Expires 标头
仅影响用户访问后的页面浏览量
已经访问过您的网站。它有
对 HTTP 数量没有影响
用户访问您的网站时发出的请求
第一次和浏览器的
缓存为空。因此影响
这种性能改进
取决于用户点击您的频率
具有已准备好的缓存的页面。 (一个“已启动
缓存”已经包含所有
页面中的组件。)我们测量了
这是在雅虎!并找到了数量
已准备好缓存的页面浏览量是
75-85%。通过使用遥远的未来 Expires
标题,您增加了数量
缓存的组件
浏览器并在后续页面中重复使用
无需发送单个字节即可查看
通过用户的互联网连接。

Short version

You need to configure your server so that it serves your website's content with different HTTP headers.

Long version

From the Yahoo! Best Practices for Speeding up Your Web Site:

Add an Expires or a Cache-Control Header

There are two aspects to this rule:

  • For static components: implement "Never expire" policy by setting far
    future Expires header
  • For dynamic components: use an appropriate Cache-Control header to
    help the browser with conditional
    requests

Web page designs are getting richer
and richer, which means more scripts,
stylesheets, images, and Flash in the
page. A first-time visitor to your
page may have to make several HTTP
requests, but by using the Expires
header you make those components
cacheable. This avoids unnecessary
HTTP requests on subsequent page
views. Expires headers are most often
used with images, but they should be
used on all components including
scripts, stylesheets, and Flash
components.

Browsers (and proxies) use a cache to
reduce the number and size of HTTP
requests, making web pages load
faster. A web server uses the Expires
header in the HTTP response to tell
the client how long a component can be
cached. This is a far future Expires
header, telling the browser that this
response won't be stale until April
15, 2010.

Expires: Thu, 15 Apr 2010 20:00:00 GMT

If your server is Apache, use the
ExpiresDefault directive to set an
expiration date relative to the
current date. This example of the
ExpiresDefault directive sets the
Expires date 10 years out from the
time of the request.

ExpiresDefault "access plus 10 years"

Keep in mind, if you use a far future
Expires header you have to change the
component's filename whenever the
component changes. At Yahoo! we often
make this step part of the build
process: a version number is embedded
in the component's filename, for
example, yahoo_2.0.6.js.

Using a far future Expires header
affects page views only after a user
has already visited your site. It has
no effect on the number of HTTP
requests when a user visits your site
for the first time and the browser's
cache is empty. Therefore the impact
of this performance improvement
depends on how often users hit your
pages with a primed cache. (A "primed
cache" already contains all of the
components in the page.) We measured
this at Yahoo! and found the number of
page views with a primed cache is
75-85%. By using a far future Expires
header, you increase the number of
components that are cached by the
browser and re-used on subsequent page
views without sending a single byte
over the user's Internet connection.

海拔太高太耀眼 2024-11-04 19:36:54

这应该可以,但不确定它是“mod_expires.c”还是“mod_expires.so” - 目前两者都不适合我。

<IfModule mod_expires.so>
  ExpiresActive On 
  ExpiresDefault "access plus 4 hours"
  ExpiresByType application/javascript "access plus 2 months"
  ExpiresByType application/javascript-x "access plus 2 months"
  ExpiresByType text/javascript "access plus 2 months"
  ExpiresByType image/jpg "access plus 2 month"
  ExpiresByType image/jpeg "access plus 2 month"
  ExpiresByType image/gif "access plus 2 month"
  ExpiresByType image/png "access plus 2 month"
  ExpiresByType text/css "access plus 2 months"
  ExpiresByType text/html "access plus 2 months"
  ExpiresByType text/xml "access plus 2 months"
  ExpiresByType text/plain "access plus 2 months"
  ExpiresByType image/x-icon "access plus 12 month"
  ExpiresByType image/icon "access plus 12 month"
  ExpiresByType application/x-ico "access plus 12 month"
  ExpiresByType application/ico "access plus 12 month"
</IfModule>

This should do it, but not sure if it's "mod_expires.c" or "mod_expires.so" - neither is working for me at the moment.

<IfModule mod_expires.so>
  ExpiresActive On 
  ExpiresDefault "access plus 4 hours"
  ExpiresByType application/javascript "access plus 2 months"
  ExpiresByType application/javascript-x "access plus 2 months"
  ExpiresByType text/javascript "access plus 2 months"
  ExpiresByType image/jpg "access plus 2 month"
  ExpiresByType image/jpeg "access plus 2 month"
  ExpiresByType image/gif "access plus 2 month"
  ExpiresByType image/png "access plus 2 month"
  ExpiresByType text/css "access plus 2 months"
  ExpiresByType text/html "access plus 2 months"
  ExpiresByType text/xml "access plus 2 months"
  ExpiresByType text/plain "access plus 2 months"
  ExpiresByType image/x-icon "access plus 12 month"
  ExpiresByType image/icon "access plus 12 month"
  ExpiresByType application/x-ico "access plus 12 month"
  ExpiresByType application/ico "access plus 12 month"
</IfModule>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文