涡轮齿轮2的CSS和JS微型/模糊控制器
tgext.minif的Python项目详细描述
关于tgext.minify
minify是一个TurboGears2中间件,可以自动缩小JavaScript 以及css和缓存。它也能混淆你的js。 基于andrémalo的rcssmin的css小型化器。 基于Ruslan Spivak的SlimIt的JS小型化/模糊化器 中间件基于alessandro molina的tgext.scss
安装
tgext.scss既可以从pypi安装,也可以从bitbucket安装:
easy_install tgext.minify
应该只对大多数用户有效
启用tgext.minify
如果tgext.pluggable可用,那么启用tgext.minify只是附加到config/app_cfg.py:
from tgext.pluggable import plug plug(base_config, 'tgext.minify')
否则,手动使用tgext.minify非常简单,只需在 #Wrap your base TurboGears 2 application with custom middleware here注释包装 app与MinifyMiddleware:
from tgext.minify import MinifyMiddleware make_base_app = base_config.setup_tg_wsgi_app(load_environment) def make_app(global_conf, full_stack=True, **app_conf): app = make_base_app(global_conf, full_stack=True, **app_conf) # Wrap your base TurboGears 2 application with custom middleware here app = MinifyMiddleware(app) return app
现在你只需要把漂亮的.css和.js文件放在public/中,它们就会被缩小。
js混淆
如果需要混淆javascript,只需将mangle_js = true添加到development.ini。 如果还要混淆全局范围,请添加mangle_js_toplevel = true。记住 如果您混淆了js,则必须连接相互依赖的js文件,否则名称空间将 搞砸了。
性能提升
下面是一个关于Paster服务bootstrap.css的基准测试的报告,有没有中间件 然后bootstrap.min.js已经缩小(不使用中间件):
$ /usr/sbin/ab -n 1000 http://localhost:8080/css/bootstrap.css Requests per second: 1135.50 [#/sec] (mean) $ /usr/sbin/ab -n 1000 http://localhost:8080/css/bootstrap.css Requests per second: 714.99 [#/sec] (mean) $ /usr/sbin/ab -n 1000 http://localhost:8080/css/bootstrap.min.css Requests per second: 806.26 [#/sec] (mean)
在这种情况下,使用tgext.minify为未统一的css提供服务甚至更快 而不是直接从内存中提供相同的css文件 (由于tgext.minify执行了缓存)。