Automatic HTML minification for Jinja2 templates
Project description
jinja2-htmlmin
Automatic HTML minification for Jinja2 templates.
Why Use This?
- Zero runtime overhead: Minification happens once at load time, not on every render
- Smaller HTML: Reduced bandwidth and faster page loads
- Drop-in compatibility: Works with any Jinja2 loader (Flask, Django, FastAPI, etc.)
- Broad Python support: Compatible with Python 3.9+
- Semantic Versioning: Predictable, reliable updates
- Zero-Clause BSD: Public domain, use freely anywhere
Installation
pip install jinja2-htmlmin
Quick Start
from jinja2 import Environment, FileSystemLoader
from jinja2_htmlmin import minify_loader
# Wrap any Jinja2 loader
# See https://htmlmin.readthedocs.io/en/latest/reference.html for options
env = Environment(
loader=minify_loader(
FileSystemLoader("templates"),
remove_comments=True,
remove_empty_space=True,
remove_all_empty_space=True,
reduce_boolean_attributes=True,
)
)
# Rendered HTML is automatically minified
html = env.get_template('index.html').render(title='My Page')
How It Works
- Template loads normally through your existing loader
- Jinja2 syntax is temporarily protected during minification
- HTML content is minified using htmlmin2
- Jinja2 syntax is restored and template compiles as usual
- Jinja2's built-in caching means this happens only once per template
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jinja2_htmlmin-1.0.1.tar.gz.
File metadata
- Download URL: jinja2_htmlmin-1.0.1.tar.gz
- Upload date:
- Size: 21.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c53398ff12799a79ab75e471e9c26be9c837d1c10103da308280bd96c45588af
|
|
| MD5 |
39a9bedae93f0ef86b14e192c930695d
|
|
| BLAKE2b-256 |
1aefd642475f0cc66c89f3347924a23a173751dc160ba44269e76db48a89f2a7
|
Provenance
The following attestation bundles were made for jinja2_htmlmin-1.0.1.tar.gz:
Publisher:
workflow.yaml on Zaczero/jinja2-htmlmin
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jinja2_htmlmin-1.0.1.tar.gz -
Subject digest:
c53398ff12799a79ab75e471e9c26be9c837d1c10103da308280bd96c45588af - Sigstore transparency entry: 326030510
- Sigstore integration time:
-
Permalink:
Zaczero/jinja2-htmlmin@a0e43373fb06c8566cd000fd15773124850c8d93 -
Branch / Tag:
refs/tags/1.0.1 - Owner: https://github.com/Zaczero
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yaml@a0e43373fb06c8566cd000fd15773124850c8d93 -
Trigger Event:
push
-
Statement type:
File details
Details for the file jinja2_htmlmin-1.0.1-py3-none-any.whl.
File metadata
- Download URL: jinja2_htmlmin-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9c6c43e88443a238e3796054c4a54cd5bd755dfc3c65b775910813988a89da3
|
|
| MD5 |
0f7ed91587ce67eddb425034b1ec0c9b
|
|
| BLAKE2b-256 |
136f89b2029eb311bcab200d875599ab6594e186d865c181d08b686f60d3d26e
|
Provenance
The following attestation bundles were made for jinja2_htmlmin-1.0.1-py3-none-any.whl:
Publisher:
workflow.yaml on Zaczero/jinja2-htmlmin
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jinja2_htmlmin-1.0.1-py3-none-any.whl -
Subject digest:
b9c6c43e88443a238e3796054c4a54cd5bd755dfc3c65b775910813988a89da3 - Sigstore transparency entry: 326030532
- Sigstore integration time:
-
Permalink:
Zaczero/jinja2-htmlmin@a0e43373fb06c8566cd000fd15773124850c8d93 -
Branch / Tag:
refs/tags/1.0.1 - Owner: https://github.com/Zaczero
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yaml@a0e43373fb06c8566cd000fd15773124850c8d93 -
Trigger Event:
push
-
Statement type: