Need help with jinja2-htmlcompress?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

mitsuhiko
122 Stars 28 Forks Other 8 Commits 13 Opened issues

Description

Compresses HTML in Jinja2 streams

Services available

!
?

Need anything else?

Contributors list

# 128
Python
Rust
Flask
sentry
8 commits

-- jinja2-htmlcompress

a Jinja2 extension that removes whitespace between HTML tags.

Example usage:

env = Environment(extensions=['jinja2htmlcompress.HTMLCompress'])

How does it work? It throws away all whitespace between HTML tags it can find at runtime. It will however preserve pre, textarea, style and script tags because this kinda makes sense. In order to force whitespace you can use {{ " " }}.

Unlike filters that work at template runtime, this remotes whitespace at compile time and does not add an overhead in template execution.

What if you only want to selective strip stuff?

env = Environment(extensions=['jinja2htmlcompress.SelectiveHTMLCompress'])

And then mark blocks with {% strip %}:

{% strip %} ... {% endstrip %}

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.