gpt4 book ai didi

wordpress - PageSpeed 建议 : Leverage browser caching. .. 如何?

转载 作者:行者123 更新时间:2023-12-02 22:21:47 26 4
gpt4 key购买 nike

我有一个 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 检查我网站的缓存状态。以下是结果:

General

The server's clock is correct.

Content Negotiation

The resource doesn't send Vary consistently.

Content negotiation for gzip compression is supported, saving 72%.

Caching

This response allows all caches to store it.

This response allows a cache to assign its own freshness lifetime.

我对结果的理解是我的网站允许缓存并且允许缓存分配自己的刷新时间。我没有使用任何 HTML“元”标签进行缓存,所以基本上,我的服务器就是这样配置的。

现在我的问题是:如何手动将脚本的“到期时间”设置为 60 分钟。我知道如何使用“.htaccess”文件来设置各种文件类型的缓存持续时间((使用FilesMatch))。但是,据推测,此方法适用于文件类型,而不适用于“.php”文件中的单个脚本。那么,如何更改 Adsense 脚本的缓存到期时间?

((这是我的第一个stackoverflow问题,所以如果有任何错误或不足,请为我指出。谢谢))

UPDATE:

在“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 现在降低了我的分数,现在有以下建议:

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)
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)

所以事情变得更加困惑。有什么帮助吗???

最佳答案

请阅读此处:

    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)

不是你的资源没有被缓存!

关于wordpress - PageSpeed 建议 : Leverage browser caching. .. 如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26280271/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com