无法在某些项目上使用浏览器

时间:2018-08-20 20:05:01

标签: javascript caching

我尝试了.htaccess中的所有不同命令,由于某些原因,一些项目无法缓存,这会使我的网站变慢。这是其中之一的示例:

    # TN - START EXPIRES CACHING #
    ExpiresActive On
    ExpiresByType text/css "access 1 month"
    ExpiresByType text/html "access 1 month"
    ExpiresByType image/gif "access 1 year"
    ExpiresByType image/png "access 1 year"
    ExpiresByType image/jpg "access 1 year"
    ExpiresByType image/jpeg "access 1 year"
    ExpiresByType image/x-icon "access 1 year"
    ExpiresByType application/pdf "access 1 month"
    ExpiresByType application/javascript "access 1 month"
    ExpiresByType text/x-javascript "access 1 month"
    ExpiresByType application/x-shockwave-flash "access 1 month"
    ExpiresDefault "access 1 month"
    # TN - END EXPIRES CACHING #
    # TN - BEGIN Cache-Control Headers
    <ifModule mod_headers.c>
    <filesMatch "\.(ico|jpe?g|png|gif|swf)$">
    Header set Cache-Control "public"
    </filesMatch>   
    <filesMatch "\.(css)$">
    Header set Cache-Control "public"
    </filesMatch>   
    <filesMatch "\.(js)$">
    Header set Cache-Control "private"
    </filesMatch>   
    <filesMatch "\.(x?html?|php)$">
    Header set Cache-Control "private, must-revalidate"
    </filesMatch>   
    </ifModule>   
    # TN - END Cache-Control Headers
    # TN - BEGIN Turn ETags Off
    FileETag None
    # TN - END Turn ETags Off

但是当我进行速度测试时,我仍然得到:

https://cdn.rlets.com/capture_static/mms/capture.js (expiration not specified)
https://cdn.rlets.com/capture_static/mms/mms.js (expiration not specified)
https://mywebsite.ico (expiration not specified)
https://www.google.com/recaptcha/api.js?onload=bwpRecaptchaCallback&render=explicit (5 minutes)
https://www.google.com/recaptcha/api2/webworker.js?hl=en&v=v1531759913576 (5 minutes)
https://www.google-analytics.com/analytics.js (2 hours)

我将JavaScript设置为过期,为什么还显示JS?知道如何解决这些问题,这真的在减慢我的网站速度吗?谢谢

1 个答案:

答案 0 :(得分:0)

您只能为您控制的脚本文件设置缓存头。这些脚本位于单独的服务器上,因此这些服务器正在设置自己的缓存策略。

也-ExpiresByType text/html "access 1 month"-这似乎不是一个好主意。如果您更新网站的页面之一,则可能要等一个月才能使访问者看到新内容。