Gzip 支持 - 是否需要文件的非 gzip 副本?
所以我决定手动 gzip 服务器上的所有文件。现在我想知道仅使用 gzip 压缩文件是否安全?或者由于某种原因我是否需要文件的“非压缩副本”?
我正在考虑:浏览器支持、机器人、Google Analytics,以及您能想到的任何其他内容...
是否安全
- 仅使用:
index.html.gz
style.css.gz
javascript.js.gz
例如:
<a herf="www.domain.com/folder/">link to folder with index.html.gz in it</a>
<script type="text/javascript" src="http://sub.domain.com/javascript.js.gz"></script>
<link rel="stylesheet" type="text/css" media="all" href="http://sub.domain.com/style.css.gz" />
如果我将其放入我的 .htaccess 文件中:
AddEncoding gzip .gz
DirectoryIndex index.html.gz
So I decided to manually gzip all my files on the serrver. Now I wonder if it's safe to only have gziped files? Or will I for some reason need to have a "non gzipped copy" of the files?
I am thinking about: Browser support, Robots, Google Analytics, anything else you can think of...
Will it be safe to only use:
index.html.gz
style.css.gz
javascript.js.gz
For example:
<a herf="www.domain.com/folder/">link to folder with index.html.gz in it</a>
<script type="text/javascript" src="http://sub.domain.com/javascript.js.gz"></script>
<link rel="stylesheet" type="text/css" media="all" href="http://sub.domain.com/style.css.gz" />
If I put this in my .htaccess file:
AddEncoding gzip .gz
DirectoryIndex index.html.gz
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
某些客户端完全有可能不支持 gzip 编码内容。
我不认为任何当前的桌面网络浏览器有这个缺点,但其他软件可能有这个缺点:搜索引擎机器人(可能不是主要的),手机浏览器,屏幕阅读器软件,......
通过不提供非-gzip 所有文件的变体,限制网站的目标受众。
It's entirely possible that some client comes along that doesn't support gzip encoded content.
I don't think any current desktop web browser has that drawback, but other pieces of software could have this: search engine bots (not the major ones, probably), mobile phone browsers, screen reader software, ...
By not providing non-gzip variations of all your files you restrict the target audience of your site.
以下代码适用于:
Htaccess 文件:
注意我已经更改了顺序(gz.html 而不是 .html.gz)
CSS 和 javascript 文件的 HTML:
请注意,我已经更改了 css 和 java 中的 gz 顺序。
.gz.html、.gz.css、.gz.js 的原因是 Safari。我找不到任何有关此的信息,但它有效。我不是专家,所以不要相信我的话是正确的。
大家觉得这个解决方案怎么样?
The following code works in:
Htaccess file:
Note that I have changed the order (gz.html instead of .html.gz)
HTML for css and javascript files:
Note that I have changed the order gz in css and java.
The reason for .gz.html, .gz.css, .gz.js is Safari. I can't find any information about this but it works. I am not an expert, so don't take my word for that it is correct.
What do you all think of this solution?