ySlow、Mod Deflate、cPanel 网站优化器和JavaScript
我刚刚开始在我的服务器上安装 mod_deflate 。我还在 cPanel 中的网站优化器中添加了以下内容:
text/html text/plain text/xml text/css text/js text/javascript
现在,该网站在加载时间方面显示出相当大的改进(几乎是 3 倍!),但 ySlow 仍然是给我“使用 gZip 压缩组件”的“E”评级。它显示 4 个 .js 组件未被压缩。
问题在于,除了 .JS 组件之外的整个网站都被正确压缩。其他所有内容,包括内联 javascript、HTML 和其他 MIME 类型都已被压缩。我没有向 htaccess 添加任何内容,因为我认为网站优化工具会处理它。但我还是不明白问题出在哪里?
有什么想法吗?
谢谢,
B.
I just got around to installing mod_deflate on my server. I also added the following to my Website Optimizer in cPanel:
text/html text/plain text/xml text/css text/js text/javascript
Now, the site shows considerable improvement in loading time (almost 3x!), but ySlow is still giving me an "E" rating for "Compress Components with gZip". It shows 4 .js components not being Compressed.
The problem is that the whole website except the .JS components is being gZipped properly. Everything else, including the inline javascript, HTML and other MIME types have been Compressed. I've not added anything to the htaccess, since I think Website Optimizer takes care of it. But I'm still not able to figure out what the problem is?
Any ideas?
Thanks,
B.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否检查过 JavaScript 所使用的 MIME 类型?您在 gzip 类型列表中列出了
text/javascript
,但有时该 MIME 类型不提供 JavaScript;它可能在text/ecmascript
、application/x-javascript
下提供,或者可能会获得像text/plain
这样的默认类型。浏览器通常不关心Content-Type
中发送的类型,因为它们关注的是标记中列出的类型,因此JavaScript 文件的内容类型可能有些奇怪。
Have you checked what MIME type the JavaScript is being served as? You listed
text/javascript
in the list of types to gzip, but sometimes JavaScript isn't served under that MIME type; it may be served undertext/ecmascript
,application/x-javascript
, or might be getting a default type liketext/plain
. Browsers don't generally care what type is sent in theContent-Type
, as it's the type listed in the<script>
tag that they pay attention to, so the content type for your JavaScript files might be something odd.宾果!意识到问题是什么。对于似乎面临同样问题的其他人:
text/javascript MIME 已过时。将其更改为 application/javascript 并且它可以正常工作! :)
Bingo! Realized what the problem is. For anyone else who seems to be facing the same problem:
text/javascript MIME is obsolete. Changed it to application/javascript and it works live a charm! :)