Closed MaartenUreel closed 2 years ago
I found out this works good:
html-minifier --collapse-whitespace --remove-comments --remove-tag-whitespace --minify-css --minify-js true --ignore-custom-fragments '[/{{[\s\S]*?}}/, /{%[\s\S]*?%}/]' -o "${HTML_FILE}" "$HTML_FILE";
For anyone looking for a similar solution, we are running this command while building our Docker image:
for HTML_FILE in `find /opt/our-application -type f -name "*.html"`
do
html-minifier --collapse-whitespace --remove-comments --remove-tag-whitespace --minify-css --minify-js true --ignore-custom-fragments '[/{{[\s\S]*?}}/, /{%[\s\S]*?%}/]' -o "${HTML_FILE}" "$HTML_FILE";
done
This way we minify all HTML files once, reducing page size but keeping our template logic intact.
Hello,
would you have any guidance on handling Django (similar to Jinja) templates?
I have currently this:
But it fails to parse, for instance on this:
Actually that specific block of HTML looks like this:
So I think my regex is too broad.
Essentially for Django templates you want to ignore:
{{ }}
(variables){% %}
(template tags), but not in{% blocktranslate ... %}{% endblocktranslate ... %}
or{% block ... %}{% block %}
.I'm also not entirely sure, I would have to get further with testing to see if everything works properly after that. But maybe someone has experience with this already and can provide a working command :)