Search code examples
sedmustachehandlebars.jsyui-compressorhttp-compression

Minify HTML files in text/html templates


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.


Solution

  • 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.