[英]How to enable gzip .js with ?ver in .htaccess?
I have .htaccess with following code 我有以下代码的.htaccess
AddType text/javascript .js
AddOutputFilterByType DEFLATE application/javascript text/javascript application/x-javascript
But Google PageSpeed Insights still telling me, that all of my .js?ver= files is not compressed. 但是Google PageSpeed Insights仍然告诉我,我的所有.js?ver =文件均未压缩。 I have checked this files with firebug and yes, content-type is "application/javascript", but compression is not working.
我已经使用firebug检查了此文件,是的,内容类型为“ application / javascript”,但压缩不起作用。 However, gzip work for css/text/etc.
但是,gzip适用于css / text / etc。
Help me find out, please. 请帮我找出来。
You could try something like this, assuming mod_headers
is enabled: 假设启用了
mod_headers
,您可以尝试这样的操作:
<IfModule mod_headers.c>
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.js $1\.js\.gz [QSA]
RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]
<FilesMatch "(\.js\.gz)$">
Header set Content-Encoding gzip
Header append Vary Accept-Encoding
</FilesMatch>
</IfModule>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.