首页 > 解决方案 > 设置 CSS 文件的过期时间

问题描述

我使用这个谷歌工具来分析我的网站。https://developers.google.com/speed/pagespeed/insights/

结果告诉我以下内容:

**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:
https://www.googletagmanager.com/gtm.js?id=GTM-XXw3 (15 minutes)
https://connect.facebook.net/en_US/fbevents.js (20 minutes)
https://connect.facebook.net/…onfig/1510218389239357?v=2.8.17&r=stable (20 minutes)
https://connect.facebook.net/…config/253358141816050?v=2.8.17&r=stable (20 minutes)
https://bat.bing.com/bat.js (30 minutes)
https://www.google-analytics.com/plugins/ua/linkid.js (60 minutes)
https://www.googleadservices.com/pagead/conversion_async.js (60 minutes)
https://www.google-analytics.com/analytics.js (2 hours)

我正在使用 Wordpress。我在哪里/如何设置到期时间?

标签: csswordpressbrowser-cachecache-control

解决方案


简短回答:您无法修改这些特定脚本的缓存设置。

更长的答案:有一些插件,如WP HummingbirdAutoptimize可以帮助您进行浏览器缓存设置以及script_loader_tag挂钩。

但是,话虽如此,请注意这些文件上的 URL。这些在 GTM、Facebook、Bing 和一些谷歌网站上。您无法控制这些过期,因为它们是通过您的跟踪/分析脚本或 iframe 从外部工具远程加载的。

这些结果是您必须忍受的,因为不值得自己托管它们并修改跟踪代码只是为了调整它们的缓存过期时间。


推荐阅读