设置 CSS 个文件的过期时间

Setting expiry of CSS files

我使用这个 google 工具来分析我的网站。 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。 Where/how我是否设置过期时间?

简答:您不能修改这些特定脚本的缓存设置。

更长的答案:有一些插件,例如 WP Hummingbird or Autoptimize that can help you with browser cache settings, as well as the script_loader_tag hook。

但是,话虽如此,请记下这些文件的 URL。这些位于 GTM、Facebook、Bing 和一些 Google 站点上。您无法控制它们的过期时间,因为它们是使用您的 tracking/analytics 脚本或 iframe 从外部工具远程加载的。

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