Skip to main content

Automatic HTML minification for Jinja2 templates

Project description

jinja2-htmlmin

PyPI - Python Version

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

  1. Template loads normally through your existing loader
  2. Jinja2 syntax is temporarily protected during minification
  3. HTML content is minified using htmlmin2
  4. Jinja2 syntax is restored and template compiles as usual
  5. Jinja2's built-in caching means this happens only once per template

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jinja2_htmlmin-1.1.0.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jinja2_htmlmin-1.1.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file jinja2_htmlmin-1.1.0.tar.gz.

File metadata

  • Download URL: jinja2_htmlmin-1.1.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for jinja2_htmlmin-1.1.0.tar.gz
Algorithm Hash digest
SHA256 4957eab8d1f44bb743d9f85b8effe38915ca65d0b8c73df12e01147f709a065c
MD5 7230e70ac6058b596c2b0c8269579599
BLAKE2b-256 b5d62b74d30b6f191471269b3e612951313b3efc694fb5ef0c5902aef090a811

See more details on using hashes here.

Provenance

The following attestation bundles were made for jinja2_htmlmin-1.1.0.tar.gz:

Publisher: ci.yaml on Zaczero/pkgs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jinja2_htmlmin-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: jinja2_htmlmin-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for jinja2_htmlmin-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 39b02b4d1b6f7b28aec7ac7ba97c00af5abbb2d38ab9bb973ff0323f4c5b692c
MD5 784808cc48aca1db6eb8abfd839e955c
BLAKE2b-256 75eb4b7d8b0d4cebe0bd404b71d812bb33f95c3691a0121113e3b7e4531d04e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for jinja2_htmlmin-1.1.0-py3-none-any.whl:

Publisher: ci.yaml on Zaczero/pkgs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page