【问题标题】:How to resolve cdn and add expire headers issues?如何解决 cdn 和添加过期标头问题?
【发布时间】:2020-05-21 02:44:11
【问题描述】:

我在 GT Metrix 上检查了我的网站性能,以下是建议:

1) 它显示为“有些静态组件不在 CDN 上”。

2) 添加 Expires 标头“有 5 个静态组件没有远期到期日期”。 解决这些问题的任何建议。

提前致谢。

【问题讨论】:

    标签: wordpress pagespeed


    【解决方案1】:

    第一个说,您正在使用未嵌入 CDN 的组件。使用 CDN,您可以更快地访问数据并自动获得最新版本。但由于 GDPR 数据保护,在许多国家/地区并不总是可以使用 CDN。

    第二个说您没有为所有数据类型设置到期日期。您可以在根文件夹的 .htaccess 文件中查找此代码,如果不存在则添加:

    <IfModule mod_expires.c>
      ExpiresActive on
    
    # document html
      ExpiresByType text/html "access plus 0 seconds"
    
    # Media: image, video, audio
      ExpiresByType audio/ogg "access plus 1 month"
      ExpiresByType image/gif "access plus 1 month"
      ExpiresByType image/jpeg "access plus 1 month"
      ExpiresByType image/png "access plus 1 month"
      ExpiresByType video/mp4 "access plus 1 month"
      ExpiresByType video/ogg "access plus 1 month"
      ExpiresByType video/webm "access plus 1 month"
    
    # CSS, JavaScript
      ExpiresByType application/javascript "access plus 1 year"
      ExpiresByType text/css "access plus 1 year"
    </IfModule>
    

    您可能需要定义更多,但很有可能通过这种方式您将完成改进。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-06
      • 2014-07-19
      • 1970-01-01
      • 2015-09-22
      • 1970-01-01
      • 2015-05-11
      • 2010-12-06
      • 2012-12-08
      相关资源
      最近更新 更多