简体   繁体   English

如何使.htaccess文件允许Safari和其他浏览器打开GZIP?

[英]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.

相关问题 如何使我的文件下载在IE和safari上正常工作? - How can I make my file download work on IE and safari? 与其他浏览器相比,如何在Safari或Mac中解决字体粗细,文本太粗体的问题? - How can i solve font-weight, text too bold, in safari or mac when compared to other browsers? 如何在 javascript 中解压缩 gzip 文件? - How can I uncompress a gzip file in javascript? 我的反应输入字段在 IOS Safari 上不起作用(我没有尝试过其他 ios 浏览器) - My react input field don't work on IOS Safari (I haven't tried other ios browsers) 如何从浏览器管理视频会议的“允许”要求? - How can I manage video conferencing “allow” requirements from browsers? 用户提交PHP表单时,如何将文本文件发送到网站上所有打开的浏览器 - How can I send a text file to all open browsers on a website when a user submits a PHP form 如何更改WordPress中的.htaccess文件,以便允许跨浏览器域访问? - How can I change the .htaccess file in WordPress so that it will allow cross browser domain access? 当我在“选择文件”之外单击时,输入文件正在打开,如何仅在单击了实际的“按钮”后才能打开它? - My input file is opening when I click outside of “choose file”, how can I make it only open if the actual “button” is clicked? 我怎么能gzip我的JavaScript和CSS文件? - How can I gzip my JavaScript and CSS files? 如何按顺序发出page.open()请求? - How can I make my page.open() requests sequentially?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM