金字塔HTML小型化程序
pyramid_html_minifier的Python项目详细描述
pyramid_html_minifier引入safehtml缩小 对于Pylons/Pyramid应用程序,无开销,由:
- Chameleon模板(ZPT基于模板实现)。Chameleon 模板仍然有效XML,因此可以使用not 过于激进的缩小选项
金字塔HTML迷你器的功能
- bandwith和性能。节省宝贵的千字节(大约50-80%取决于您的模板)。 这对于bandwith的使用和改进性能非常重要, 更重要的是如果你必须管理一个大而胖的 Pylons/Pyramid为基础的网站,流量很大。 见https://www.npmjs.com/package/html-minifier
- 无开销。缩小基于一个构建步骤(一种 基于咕噜声/咕噜声的collectstatic)。所以在飞行中不能缩小
- 安全模板/html缩小。它甚至可以与^{tt8}一起工作$ 和slots。 这种模式已在生产网站上采用,没有任何问题 一年后。所以我敢说这是一个安全的模式 一年检疫没有任何问题。你只应该 记住禁用过于激进的缩小选项(参见下一步 部分)
金字塔HTML迷你器的功能
什么pyramid_html_minifier介绍:
- 自定义的.html呈现程序(解释为Chameleon模板)
- 支持distvsapp,常用于Yeoman 项目。app将用于开发,而dist 在生产模式下(基于模板缩小生成)。
这样您就可以开始开发静态模拟应用程序(甚至 使用Yeoman工作流并使用 由宏和槽丰富的修改过的html文件为Chameleon 模板。
如何使用棱锥体HTML小型化程序
在这里您可以看到如何在您的 Pylons/Pyramidweb应用程序:
- 将Chameleon模板文件放入templates/app/master.html及其 templates/dist/master.html(扩展名为.html)中的缩小版本 重要)。显然不要手工缩小,在 开发工作流程及其相关的自动化工具。 此包不提供任何gulp或grunt配置, 您应该创建自己的设置
- 向注册一个普通的Pylons/Pyramid可调用视图 renderer="your_plugin:templates/{0}/master.html"。{0}只是 一个占位符,pyramid_html_minifier将根据您的 设置。请参见下一步
- 告诉pyramid_html_minifier如果您想选择标准模板或 将pyramid_html_minifier.placeholder设置添加到 .ini文件。开发的典型值是app(默认值)。 而dist通常用于生产环境。 示例:pyramid_html_minifier.placeholder = dist
- 将pyramid_html_minifier添加到金字塔中。包括设置
最后一个.ini文件应该如下所示:
pyramid.includes = ... pyramid_html_minifier ... pyramid_html_minifier.placeholder = dist
安全缩小选项
我建议将Yeoman工作流集成到 Pylons/Pyramidproject获得最佳开发体验。
我建议使用html-minifierminificator及其朋友gulp-html-minifier 禁用过于激进的HTML缩小选项。
尤其要确保启用了keepClosingSlash选项,并且 removeAttributeQuotes已禁用。
在这里您可以看到一个实际的工作配置示例:
const htmlMinifierOptions = { collapseBooleanAttributes: true, collapseWhitespace: true, removeComments: true, removeCommentsFromCDATA: true, removeEmptyAttributes: true, removeRedundantAttributes: true, useShortDoctype: true, keepClosingSlash: true, } ... gulp.task('html', ['styles'], () => { const assets = $.useref.assets({searchPath: ['.tmp', 'app', '.']}); return gulp.src('app/*.html') .. .pipe($.if('*.html', $.htmlMinifier(htmlMinifierOptions))) ... .pipe(gulp.dest('dist'));
链接
在这里您可以找到使用pyramid_html_minifier:
的项目有关使用相同模式的案例研究的更多详细信息:
0.1(2015-08-03)
- 初始版本