不使用 mod_gzip 和 mod_deflate 压缩 CSS 和 JS
我想压缩服务器上的 CSS 和 JS 文件,以最大程度地减少加载时间和问题。
我的托管是 Streamline.net(这是一个大错误,永远不要去那里),由于安全问题,他们不会激活 mod_gzip 和 mod_deflate。
有没有人有另一种方法来压缩这些类型的文件(如果可能的话,还有图像文件)而不采用 mod_gzip 和 mod_deflate 的方法。
答案将非常受欢迎。
I would like to compress the CSS and JS files on my server to minimise load times, problem.
My hosting is with Streamline.net (big mistake, never go there) who will not activate mod_gzip and mod_deflate due to security issues.
Does anyone have another way to compress these types of files (and image files too if poss) without going the way of mod_gzip and mod_deflate.
Answers would be hugely welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
是的,答案是缩小。
显然,它的压缩程度不如 gzip 或 放气。但这很有帮助,而且使用正确的工具很容易做到。
Yes, the answer is Minification.
Obviously, it will not compress as much as gzip or deflate. But it helps, and it is very easy to do with the right tools.
您可以通过脚本运行文件,该脚本将为您进行 gzip 文件并添加适当的过期标头。
要么设置 URL 重写,要么手动重写 URL:
在
compress.php 中,您可以执行类似的操作
,显然这也可以扩展到 提供 HTTP 缓存,和/或即时缩小,进一步加快访问者的浏览速度。
You can run your files through a script which would gzip them for you and add appropriate expiration headers.
Either set up an URL rewrite, or rewrite the URLs manually:
becomes
and in compress.php, you can do something like
Obviously this can be extended to also provide HTTP caching, and/or on-the-fly minification, further speeding up your visitors' browsing.
您可以自己对 CSS 和 JavaScript 文件进行 gzip,然后上传,而不是让 mod_gzip 动态对 CSS 和 JavaScript 文件进行 gzip。
这确实在上传 CSS 和 JavaScript 之前引入了另一个步骤,但它确实有效,与 mod_gzip 相比,甚至可能为每个请求节省一点点服务器处理时间。
在 Mac OS X 上,在命令行上对文件进行 gzip 压缩非常简单,例如:
确保这些文件使用正确的内容类型标头提供服务。
Instead of getting mod_gzip to gzip your CSS and JavaScript files dynamically, you can gzip them yourself, then upload them.
This does introduce another step before you upload CSS and JavaScript, but it works, and maybe even saves a tiny bit of server processing time for each request compared to mod_gzip.
On Mac OS X, gzipping a file on the command line is as easy as, e.g.:
Make sure these files get served with the right content-type header though.
顺便说一句:如果图像已经以压缩格式保存,并且最大压缩对用户来说仍然看起来不错,那么压缩图像就没有什么好处。
Just as a sidenote: Compressing images would not be beneficial if these are already saved in a compressed format with the maximum compression that still looks good to the user.
大多数编程语言都支持某些数据或文件压缩格式,例如 ZLIB 或 GZIP。因此,您可以使用编程语言来压缩具有这些格式之一的文件。
Most programming languages support some data or file compression formats like ZLIB or GZIP. So you could use a programming language to compress your files with one of these formats.