【发布时间】:2014-12-04 11:49:50
【问题描述】:
我有一个带有我自己创建的自定义主题的 wordpress 网站。目前,我正在研究“Google PageSpeed Insights”的建议,以改善我网站上的用户体验。
PageSpeed 建议“利用浏览器缓存”。结果如下:
**Leverage browser caching** Setting an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources from local disk rather than over the network. Leverage browser caching for the following cacheable resources: http:.//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js (60 minutes) http:.//pagead2.googlesyndication.com/pagead/osd.js (60 minutes) http:.//www.google.com/…callback%22%3A%22__gcse.sacb%22%7D%5D%7D (60 minutes)
因此,基本上,建议我将 Adsense 脚本缓存的“到期时间”设置为 60 分钟。
我尝试通过 REDbot 检查我的网站的缓存状态。结果如下:
常规
服务器的时钟是正确的。
内容协商
资源没有一致地发送 Vary。
支持 gzip 压缩的内容协商,节省 72%。
缓存
此响应允许所有缓存存储它。
此响应允许缓存分配自己的新鲜度生命周期。
我对结果的理解是,我的网站允许缓存,并且允许缓存分配自己的刷新时间。我没有使用任何 HTML “元”标签进行缓存,所以基本上,我的服务器就是这样配置的。
现在我的问题是:如何手动将脚本的“过期时间”设置为 60 分钟。 我知道如何使用“.htaccess”文件为各种文件类型设置缓存持续时间((使用 FilesMatch))。但是,据推测,此方法适用于文件类型,而不是“.php”文件中的单个脚本。 那么,如何更改 AdSense 脚本的缓存过期时间?
(((这是我的第一个stackoverflow问题,如果有任何错误或不足之处,请指出来..谢谢))
更新:
在“Andrew”的回答之后,我将以下内容添加到我的 .htaccess 文件中。
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 hour"
ExpiresByType image/jpeg "access plus 1 hour"
ExpiresByType image/gif "access plus 1 hour"
ExpiresByType image/png "access plus 1 hour"
ExpiresByType text/css "access plus 1 hour"
ExpiresByType text/html "access plus 1 hour"
ExpiresByType text/x-javascript "access plus 1 hour"
ExpiresByType image/x-icon "access plus 1 hour"
ExpiresDefault "access plus 1 hour"
</IfModule>
## EXPIRES CACHING ##
但它给了我奇怪的结果。 Pagespeed 现在降低了我的分数,现在有以下建议:
利用浏览器缓存设置到期日期或最长期限 静态资源的 HTTP 标头指示浏览器加载 以前从本地磁盘下载的资源,而不是通过 网络。将浏览器缓存用于以下可缓存 资源:
http.://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js (60 minutes) http.://pagead2.googlesyndication.com/pagead/osd.js (60 minutes) http.://www.google.com/…callback%22%3A%22__gcse.sacb%22%7D%5D%7D (60 minutes) http.://www.mananatomy.com/…heme/images/mananatomy_logo_modified.jpg (60 minutes) http.://www.mananatomy.com/…mages/mananatomy_logo_modified_small.jpg (60 minutes) http.://www.mananatomy.com/…s/mananatomy-theme/images/sidebar_bg.jpg (60 minutes) http.://www.mananatomy.com/…ontent/themes/mananatomy-theme/style.css (60 minutes) http.://www.mananatomy.com/…t/uploads/2010/12/basic-anatomy-logo.jpg (60 minutes) http.://www.mananatomy.com/…nt/uploads/2010/12/body-systems-logo.jpg (60 minutes) http.://www.mananatomy.com/…ntent/uploads/2010/12/histology-logo.jpg (60 minutes)
所以它变得更加混乱。有什么帮助???
【问题讨论】:
标签: wordpress caching pagespeed