利用浏览器缓存js?ver = [英] Leverage Browser Caching js?ver=

查看:252
本文介绍了利用浏览器缓存js?ver =的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的杠杆浏览器缓存面临一个奇怪的问题。在我的 .htaccess 中,使用以下命令:

I'm facing an odd problem with my Leverage Browser Caching. In my .htaccess I use the following:

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
## EXPIRES CACHING ##

成功缓存了我的网站。但是我面临的问题是它缺少一些外部JS文件:

This successfully caches my website. But the issue I'm facing is it is missing out some non-external JS files:

http://example.com/wp-content/themes/tracks/js/build/production.min.js?ver=4.7.2 (2 days)
http://example.com/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.4.1 (2 days)
http://example.com/wp-includes/js/jquery/jquery.js?ver=1.12.4 (2 days)
http://exmaple.com/wp-includes/js/wp-embed.min.js?ver=4.7.2 (2 days)
http://example.com/wp-includes/js/wp-emoji-release.min.js?ver=4.7.2 (2 days)

我试图通过添加以下行来修复它,但结果仍然相同:

I tried to fix it by adding the following lines, but the result was still the same:

ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/json "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"

是否知道为什么不使用 js?ver = 以及如何解决此问题?如果有帮助的话:

Any idea why it is not picking up the js?ver= and how to fix this problem? In case it helps:

托管: Hostinger

Hosting: Hostinger

服务器: Apache 2.4

Server: Apache 2.4

推荐答案

好,我设法解决了这个问题。我使用以下四行是正确的:

OK, I managed to fix the issue. I was correct in using the following four lines:

ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/json "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"

但是,出于某些原因, access plus 部分周围的引号引起了卷曲。因此,这将返回 500 503 服务器错误。替换引号后,它已经解决了我的问题,现在也正确缓存了 js?ver = 文件。

However, the quotation marks around the access plus section are for some reason curly quotations. This was therefore returning 500 and 503 server errors. After replacing the quotation marks it has since fixed my issue and now correctly caches js?ver= files too.

我最终的杠杆浏览器缓存代码如下所示:

My final Leverage Browser Caching code looks like this:

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/json "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
## EXPIRES CACHING ##

这篇关于利用浏览器缓存js?ver =的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆