我怎样才能让我的.htaccess文件允许Safari浏览器和放大器;其他浏览器打开GZIP? [英] How can I make my .htaccess file allow Safari & other browsers to open GZIP?

查看:308
本文介绍了我怎样才能让我的.htaccess文件允许Safari浏览器和放大器;其他浏览器打开GZIP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用.htaccess文件,让我的网页调用gzip压缩JavaScript文件。

I'm using an .htaccess file to allow my pages to call gzipped JavaScript files.

它工作正常,在IE8和放大器; FF3,但剧本没有在Safari浏览器(或浏览器)加载。

It works fine in ie8 & ff3, but the script is not loaded in Safari (or Chrome).

下面是我使用的.htaccess文件:

Here is the .htaccess file I'm using:

<files *.js.gz>
ForceType text/javascript
Header set Content-Encoding: gzip
</files>

然后,例如,我可以从我的HTML页面调用JS文件:

Then, for example, I can call JS files from my HTML pages:

<script src="foo.js.gz"></script>

我如何修改上面的.htaccess code得到它的工作的Safari浏览器(现在仍然适用于其他浏览器)?

How can I modify the above .htaccess code to get it working for Safari (and still work for other browsers)?

推荐答案

我假设你想用gzip COM pression下载速度更快的资产和文本内容。这对于加快你的网站有很大的技术。

I assume you're trying to use Gzip compression for faster downloads of assets and text content. It's a great technique for speeding up your site.

Safari浏览器,Chrome和IE6都有问题,gzip压缩的下载。此外,Apache会做gzip的COM pression的你,有没有需要手动gzip压缩文件。试试这个片断:

Safari, Chrome, and IE6 all have problems with Gzipped downloads. Also, Apache will do the gzip compression for you, there is no need to manually gzip files. Try this snippet:

# This uses mod_deflate, which is pretty standard on Apache 2.  Loading
# mod_deflate looks like this:
#
#   LoadModule deflate_module modules/mod_deflate.so
#
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \\bMSIE !no-gzip !gzip-only-text/html

这应安全地gzip压缩的所有文字之前,它是来自Apache送出,只为支持它的浏览器。您可以链接到JavaScript和其他资产正常,只是 myscript.js ,没有gz的扩展或COM pression在磁盘上。

That should safely gzip all text before it's sent out from Apache, and only for browsers that support it. You can link to JavaScript and other assets normally, just myscript.js, with no gz extension or compression on disk.

这篇关于我怎样才能让我的.htaccess文件允许Safari浏览器和放大器;其他浏览器打开GZIP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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