"Compressing" your html?

152 views
Skip to first unread message

Christian Gloddy

unread,
Mar 25, 2014, 12:11:03 PM3/25/14
to nunj...@googlegroups.com
What the easiest way to "compress" your html (aka remove unneeded whitespace) in nunjucks? Many template solutions simply make this an available setting.

Christian

Alberto Gimeno Brieba

unread,
Mar 25, 2014, 2:31:50 PM3/25/14
to nunj...@googlegroups.com
As far as I know this is not possible. Nunjucks is a general purpose templating engine. You can generate HTML or anything else. Well, there is the autoescaping feature, but I think that's all.

You could parse the output and then post-process it with other library. Nevertheless it could be potentially dangerous to just remove whitespaces. For example for a "script" tag you could broke the code.

Additionally some CSS properties are sensitive to whitespaces such as "display: inline-block"

James Long

unread,
Mar 25, 2014, 2:50:51 PM3/25/14
to Alberto Gimeno Brieba, nunj...@googlegroups.com
What Alberto said. Nunjucks is a string templating library; it is not
aware of HTML. This is a limitation of that.

Someone is asking for a tag to do this within the tag, it has a
(somewhat hacky) solution:
https://github.com/jlongster/nunjucks/issues/207

- James
> --
> You received this message because you are subscribed to the Google Groups
> "Nunjucks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nunjucks+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Christian Gloddy

unread,
Mar 25, 2014, 3:40:55 PM3/25/14
to nunj...@googlegroups.com
It certainly can have downsides if done inappropriately, but it's another step in getting the page to render as quickly as possible. Google's own recommendations even suggest doing so.
Reply all
Reply to author
Forward
0 new messages