javascript - 缩小 jQuery tmpl html 模板

标签 javascript html templates gruntjs minify

我想缩小我的 .html 文件。我试着用 grunt-contrib-htmlmin 缩小, grunt-processhtml .他们实际上无法缩小。然后我意识到我所有的 html 元素都包含在 jQuery.tmpl 中.这些缩小工具似乎不涉及脚本标签。所以我有一堆模板如下所示:

<script id='wrapper' type='text/x-jquery-tmpl'>
  <div class='person-wrapper'>
    {{html $item.html()}}
  </div>
  <!-- many html tags -->
</script>

我的问题是如何缩小 (jQuery.tmpl) 模板?我正在使用 Gruntjs 来缩小 .css、.js 文件。但任何工具或插件都值得赞赏。

最佳答案

尝试查看 htmlcompressor .根据他们的文档,它应该压缩模板标签内的代码:

Any content within <pre>, <textarea>, <script> and <style> tags will be preserved and remain untouched (with the exception of <script type="text/x-jquery-tmpl"> tags which are compressed as HTML).

它是 Java 库,但它也有 grunt plugin .

希望对您有所帮助。

关于javascript - 缩小 jQuery tmpl html 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21462615/

相关文章:

javascript - 这是一种加 1 然后在一秒后加 2 和 3 等的方法吗

c++ - 如何检查模板参数是否为结构/类?

javascript - 单击 div 的滚动条会触发 I.E 中的模糊事件

java - 在 java 中运行 d3 javascript

javascript - 使用 JavaScript 在页面加载时显示弹出窗口

c++ - 指向类型名成员的指针

c++ - 仅在 Manager 类中创建对象

javascript - 更改现有网页以将属性值显示为文本

javascript - 比较和索引 Javascript 数组中的正则表达式

html - 如何强制 Safari 重新绘制位置 :fixed elements on scroll?