2

我正在使用网页测试来了解我的网站性能。我发现缓存静态内容存在问题,即“利用浏览器缓存静态资产:88/100”

失败 - (没有最大年龄或过期)

我该如何解决这个问题?

我的 htaccess 看起来像:

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/png
AddOutputFilterByType DEFLATE image/jpg
AddOutputFilterByType DEFLATE image/gif

# Or, compress certain file types by extension:
<ifModule mod_deflate.c>
<filesMatch ".(js|css|html|htm|php|jpg|jpeg|woff|eot)$">
SetOutputFilter DEFLATE
</FilesMatch>
</ifModule>

# Direct Apache to send all HTML output to the mod_pagespeed output handler.
AddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER text/html

谢谢

4

2 回答 2

0

除了放气设置之外,您还想添加一些过期控制来管理浏览器缓存。我使用了以下效果很好。根据您网站上文件的具体情况,您可能还需要添加音频和视频文件。

从记忆中,当您将到期时间设置为至少 1 个月时,webpagetest 喜欢它,因此您可能还想调整 1 周设置

祝你好运!

################
# Enable expiration control
ExpiresActive On

# Default expiration: 1 hour after request
ExpiresDefault "now plus 1 hour"

# CSS and JS expiration: 1 week after request
ExpiresByType text/css "now plus 1 week"
ExpiresByType application/javascript "now plus 1 week"
ExpiresByType application/x-javascript "now plus 1 week"

# Image files expiration: 1 month after request
ExpiresByType image/bmp "now plus 1 month"
ExpiresByType image/gif "now plus 1 month"
ExpiresByType image/jpeg "now plus 1 month"
ExpiresByType image/jp2 "now plus 1 month"
ExpiresByType image/pipeg "now plus 1 month"
ExpiresByType image/png "now plus 1 month"

########## End - Optimal expiration time
于 2013-05-17T23:59:32.990 回答
0
ExpiresActive on
ExpiresDefault "access plus 1 month"
ExpiresByType text/html "now plus 0 second"
<FilesMatch "\.(css|js|png|bmp|ico|htm|gff|html|js|jpg|jpeg|gif|gcf)$">
FileETag MTime Size
ExpiresDefault "access plus 1 month"
</FilesMatch>

这是我在主机上更改缓存控制后在 .htaccess 中的内容。但即使我改变了这些,当我运行webpagetest.org时似乎也没有任何好的效果。我需要等到以前的缓存过期并再次运行它。这行得通。欢呼!. 在这里我找到了一个有用的链接。 http://httpd.apache.org/docs/current/mod/mod_expires.html

于 2017-01-14T20:14:22.023 回答