Do most shared hosts handle gzipped files?

我怕爱的太早我们不能终老 提交于 2020-02-06 05:26:31

问题


I get them theoretically, but I'm grappling with gzipping files in practice. How should I go about gzip compressing my files, and what needs to be done in order to use them on a shared host?

Would the following work?

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:Accept-Encoding} .*gzip.*
RewriteRule ^/(.*)\.js$ /$1.js.gz [L]
RewriteRule ^/(.*)\.css$ /$1.css.gz [L]
AddEncoding x-gzip text.gz

回答1:


You're probably going to have trouble with the MIME type of the decompressed content still being application/gzip-compressed rather than text/css or text/javascript.

What is your purpose in doing this? If you just want to cut down on network transfers, you should do that using mod_deflate, eg.:

AddOutputFilterByType DEFLATE text/css text/javascript

and let Apache worry about compressing the transfers themselves on the fly. Otherwise browsers that can't negotiate gzip will be stuck.

I would hope a decent shared host would have already set compression for you. Use an online tool to check whether your stylesheets are being served compressed.



来源:https://stackoverflow.com/questions/2682155/do-most-shared-hosts-handle-gzipped-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!