[英]How can I make my .htaccess file allow Safari & other browsers to open GZIP?
I'm using an .htaccess file to allow my pages to call gzipped JavaScript files. 我正在使用.htaccess文件来允许我的页面调用gzip压缩的JavaScript文件。
It works fine in ie8 & ff3, but the script is not loaded in Safari (or Chrome). 在ie8和ff3中可以正常工作,但脚本未加载到Safari(或Chrome)中。
Here is the .htaccess file I'm using: 这是我正在使用的.htaccess文件:
<files *.js.gz>
ForceType text/javascript
Header set Content-Encoding: gzip
</files>
Then, for example, I can call JS files from my HTML pages: 然后,例如,我可以从HTML页面调用JS文件:
<script src="foo.js.gz"></script>
How can I modify the above .htaccess code to get it working for Safari (and still work for other browsers)? 如何修改上面的.htaccess代码以使其在Safari上运行(并在其他浏览器上仍然运行)?
I assume you're trying to use Gzip compression for faster downloads of assets and text content. 我假设您正在尝试使用Gzip压缩来更快地下载资产和文本内容。 It's a great technique for speeding up your site. 这是加快网站速度的绝佳技术。
Safari, Chrome, and IE6 all have problems with Gzipped downloads. Safari,Chrome和IE6都存在Gzipped下载问题。 Also, Apache will do the gzip compression for you, there is no need to manually gzip files. 另外,Apache将为您执行gzip压缩,无需手动gzip文件。 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
That should safely gzip all text before it's sent out from Apache, and only for browsers that support it. 在从Apache发送出去之前,这应该安全地压缩所有文本,并且仅适用于支持该文本的浏览器。 You can link to JavaScript and other assets normally, just myscript.js
, with no gz extension or compression on disk. 您可以正常链接到JavaScript和其他资产,仅链接到myscript.js
,而无需gz扩展名或磁盘压缩。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.