大多数共享主机是否处理gzip压缩文件? [英] Do most shared hosts handle gzipped files?

查看:122
本文介绍了大多数共享主机是否处理gzip压缩文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从理论上得到他们,但是我在实践中抓住gzipping文件。我应该如何进行gzip压缩我的文件,需要做什么才能在共享主机上使用它们?

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?

以下工作?

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


推荐答案

对于解压缩内容的MIME类型仍然有麻烦,仍然是 application / gzip-compressed ,而不是 text / css text / javascript

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.

您的目的是什么?如果你只是想减少网络传输,你应该使用 mod_deflate ,例如:

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

压缩传输本身在飞行。否则不能协商gzip的浏览器将被阻塞。

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.

这篇关于大多数共享主机是否处理gzip压缩文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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