如何压缩文件以加快您的网站速度?
我已经在 Drupal 中构建了这个网站。这不是 Drupal 相关的问题。 我正在尝试加快加载时间,因此我使用 Google Page Speed 脚本。 问题是最大的问题是压缩一些文件。 由于我的 Drupal 安装中有几个“加速”模块,这些“未压缩”文件不是 Drupal 而是第三方相关的。 例如,它们是我的计数器图像和来自视频播放器的 js 文件:
如果是的话http://www.mysite.org/jwplayer/jwplayer.js< /a> ...
如何我要压缩这些文件吗?我应该将它们放在 zip 中以指向压缩文件吗?但这些文件会按预期工作吗?我的意思是,指向压缩的 .js 文件,还是压缩计数器的跟踪器?
我不知道该如何处理这些错误。我还没有找到关于如何压缩并指向在线压缩但有效文件的新手解释。
谢谢!
罗莎蒙达
I´ve got this site build in Drupal. This is not a Drupal related question.
I´m trying to speed up the load time, so I´ve made a test using Google Page Speed script.
The thing is that the biggest issue is compressing some files.
As I´ve got several "speed up" modules in my Drupal installation, these "uncompressed" files are not Drupal but third party related.
They are, in example, my counter image and a js file from a video player:
Si se comprime http://www.mysite.org/jwplayer/jwplayer.js ...
Si se comprime http://www.w3counter.com/tracker.js ...
How do I compress those files? Should I just put them inside a zip in point to a zipped file? But would those files work as expected? I mean, Pointing to a zipped .js file, or zipping the counter´s tracker?
I have no idea on what to do about those errors. I haven´t found a newbie explanation yet about how to compress and point to a compressed yet working file online.
Thanks!
Rosamunda
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Web 服务器可以在将文件提供给浏览器之前对其进行压缩。如果您使用的是最新版本的 Apache,启用模块 mod_deflate 可能会就足够了。 (至少我没有做任何其他事情,Firebug 对所有 HTML/CSS/JS 请求显示
Content-Encoding: gzip
并且 Page Speed 竖起了大拇指。)The web server can compress files before serving them to the browser. If you are using a recent version of Apache, enabling the module mod_deflate may be enough. (At least I did not do anything else and Firebug shows
Content-Encoding: gzip
for all HTML/CSS/JS requests and Page Speed gives it thumbs up.)正如 Dmitry Leskov 所说 - 打开您的网络服务器自动压缩模块将压缩从您的盒子(在本例中为 jwplayer)提供的所有内容,尽管它不会压缩从服务器外部(w3counter.com)拉取的资源。
如果您的网站速度很慢,可能不是因为“前端”问题(从 PageSpeed 脚本获得),而是因为您的“后端”速度很慢,例如数据库或 Drupal 引擎本身;如果你的页面需要 5 秒才能生成,无论你的 JavaScript 压缩得多么好,网站总是会感觉很慢。更重要的是,因为 JavaScript 资源通常缓存在浏览器上……
拼图的两个部分都值得一看。找出正在发生的情况的一种快速而肮脏的方法是使用 Firebug 插件来查看服务器响应请求需要多长时间。
As Dmitry Leskov says - switching on your web servers automatic compression module will compress everything served from your box (the jwplayer, in this instance), though it won't compress resources pulled from outside your server (w3counter.com).
If your site is slow, it may not be because of "front-end" issues (which you get from the PageSpeed script), but because your "back-end" is slow, e.g. the database, or the Drupal engine itself; if it takes 5 seconds for your page to be generated, no matter how well-compressed your JavaScript, the site's always going to feel slow. Even more so because JavaScript resources are often cached on the browser...
It's worth looking at both parts of the jigsaw. A quick and dirty way to find out what's going on is to use the Firebug plug-in to see how long it takes for your server to respond to requests.