在文本/ html模板中缩小HTML文件 [英] Minify HTML files in text/html templates
问题描述
我使用小胡子/车把模板。 >< script id =contact-detail-templatetype =text / html>
< div> ...要压缩的内容< / div>
< / script>
我希望压缩/缩小模板中的HTML文件以获得最佳压缩效果。
YUIcompressor,闭包不起作用,因为它们认为它是脚本并给我脚本错误。
HTMLCompressor不会触摸他们甚至认为它是一个脚本。
如何使用text / html类型缩小脚本标记中的内容?
我可以使用图书馆吗?
如果不是,sed或egrep是一个更好的方法?你有sed / egrep语法删除空行(只有空格或制表符),删除所有标签,修剪多余的空格吗?
谢谢。
sed -es / ^ [\t] * // g-e/ ^ $ / d yourfile
这将从开始时删除所有额外的空格和制表符,并删除所有空行。
sed -es / ^ [\t] * // g-e:a; N; $!ba; s / \\\
这将删除所有额外的空格和制表符,并连接所有的代码。
// gyourfile
对不起,我错过了什么。
I use mustache/handlebar templates.
eg:
<script id="contact-detail-template" type="text/html">
<div>... content to be compressed </div>
</script>
I am looking to compress/minify my HTML files in the templates for the best compression.
YUIcompressor, closure does not work as they think that it is script and gives me script errors.
HTMLCompressor does not touch them even as it thinks that it is a script.
How do I minify the content in the script tags with type text/html? Can I use a library? If not, is sed or egrep a preferable way? Do you have sed/egrep syntax to remove empty lines (with just spaces or tabs), remove all tabs, trim extra spaces?
Thanks.
sed -e "s/^[ \t]*//g" -e "/^$/d" yourfile
This will remove all the extra spaces and tabs from the begining, and remove all empty lines.
sed -e "s/^[ \t]*//g" -e ":a;N;$!ba;s/\n//g" yourfile
This will remove all the extra spaces and tabs from the begining, and concatenate all your code.
Sorry if i missed something.
这篇关于在文本/ html模板中缩小HTML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!