开发者

How can I compress ALL my JavaScript files server-side with Apache?

开发者 https://www.devze.com 2023-03-04 21:01 出处:网络
Hey guys, After running Google Page Speed, my Compression Results were red. Google Page Speed said almost all my files — JS, CS开发者_StackOverflow中文版S, etc. — should be compressed with gzip.

Hey guys,

After running Google Page Speed, my Compression Results were red. Google Page Speed said almost all my files — JS, CS开发者_StackOverflow中文版S, etc. — should be compressed with gzip.

I added the following line to my .htaccess file.

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/css text/plain text/javascript text/xml application/xhtml+xml application/x-httpd-php
</IfModule>

Now the Compression Results look slighly better - yellow! However Page Speed keeps saying that I should compress all my JavaScript libs and plugins. I could reduce them by 65% with gzip.

Shouldn't all my JS files be compressed now when I have text/javascript set as DEFLATE?


Apache also uses mime type application/x-javascript, this howto explains how to set it.

Basically it says you need to use:

<Location />
    AddOutputFilterByType DEFLATE application/x-javascript
</Location>

On a side note, you might also consider using a minifier/compressor like the YUI compressor or a specific compressor that integrates with your software.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号