服务器端自动缩小? [英] Server-side auto-minify?

查看:30
本文介绍了服务器端自动缩小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法自动缩小静态内容,然后自动从缓存中提供它?类似于 mod_compress/mod_deflate 工作?最好是我可以与压缩结合使用的东西(因为压缩有更明显的好处).

Is there any way to automatically minify static content and then serve it from a cache automatically? Similar to have mod_compress/mod_deflate work? Preferably something I could use in combination with compression (since compression has a more noticeable benefit).

我的偏好是可以与 lighttpd 一起使用的东西,但我找不到任何东西,所以任何可以做到这一点的网络服务器都会很有趣.

My preference is something that works with lighttpd but I haven't been able to find anything, so any web server that can do it would be interesting.

推荐答案

可以试试nginx的第三方Strip模块:

You can try nginx's third party Strip module:

http://wiki.nginx.org/NginxHttpStripModule

您使用的任何模块都会删除空格.通过使用理解您正在缩小的任何内容的缩小器,您将获得更好的结果.例如Google 的 Closure javascript 编译器.

Any module you use is just going to remove whitespace. You'll get a better result by using a minifier that understands whatever you're minifying. e.g. Google's Closure javascript compiler.

知道什么是变量并缩短它的名称已经足够聪明了.空白去除器无法做到这一点.

It's smart enough to know what a variable is and make it's name shorter. A whitespace remover can't do that.

除非您的网站流量非常低,否则我建议您离线缩小.但是如果你想在你的实时环境中缩小我建议使用 nginx 的代理缓存.(抱歉,我没有足够的声誉发布多个链接)

I'd recommend minifying offline unless your site is very low traffic. But if you want to minify in your live environment I recommend using nginx's proxy cache. (Sorry but I don't have enough reputation to post more than one link)

或者,您可以查看 memcached 以获取内存中缓存,或者查看 Redis 以获取相同的内容但具有磁盘备份.

Or you can look into memcached for an in-memory cache or Redis for the same thing but with disk backup.

这篇关于服务器端自动缩小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆