django-htmlmin icon indicating copy to clipboard operation
django-htmlmin copied to clipboard

Minifying template creating problem

Open ET-CS opened this issue 11 years ago • 1 comments

Hi. I am using django-htmlmin to pre-minify my html templates before rendering them on-line. I prefer to pre-minifying my templates instead of minifying the rendered html each time the server is rendering a template in terms of performance.

It's working great but I came across a problem with a template Including the following line:

...
<input type="checkbox" name="remember" value="true" {{if .Remember}}checked{{end}}>
...

Minifying the whole document changes this input into:

<input .remember}}checked{{end}}="" name="remember" type="checkbox" value="true" {{if=""/>

Which is now wrong and causes my (Golang) template engine to fail with bad syntax error.

Any idea for why this it happens? Is there a way to fix this? or maybe some workaround to tell htmlmin to ignore this line or parse it differently?

Please tell me if I can help with more information. Thank you in advance

ET-CS avatar Nov 22 '14 04:11 ET-CS

Another similar problem when minifying mako templates (and not pure html):

<table>
    <thead>
        <tr>
            <th>column1</th>
            <th>column2</th>
            <th>column3</th>
        </tr>
    </thead>
    <tbody>
    {% for e in events %}
    <tr>
        <td>{{ e.date }}</td>
        <td>{{ e.name }}</td>
        <td>{{ e.desc }}</td>
    </tr>
    {% endfor %}
    </tbody>
</table>

would become:

<table>...<td>/{{ e.name }}</td>...</table>{% for e in events %} {% endfor %}

which is not ok as the table is extracted from the for loop.

Is there is something that can be done to fix this issue or htmlmin could only be used for pure htmls and not with templates?

ET-CS avatar Feb 07 '15 12:02 ET-CS