Skip to main content

django-template-minifying-loader

Django application, providing simple template loader. It reduces HTML output in templates by stripping out whitespace characters between HTML and django template tags. This is an update of django-template-minifier that works with django 1.10.

Things to note:

Installation

pip install django-template-minifying-loader

Basic usage

Modify Your Django project settings’s module.

For production (note cached loader):

TEMPLATES = [
  {
      'DIRS': [
          str(APPS_DIR.path('templates')),
      ],
      'OPTIONS': {
          'loaders': [
              'django.template.loaders.cached.Loader',
              'template_minifying_loader.loaders.filesystem.Loader',
              'template_minifying_loader.loaders.app_directories.Loader',
          ],
      },
  },
]

For development (each refresh reloads template):

TEMPLATES = [
  {
      'DIRS': [
          str(APPS_DIR.path('templates')),
      ],
      'OPTIONS': {
          'loaders': [
              'template_minifying_loader.loaders.filesystem.Loader',
              'template_minifying_loader.loaders.app_directories.Loader',
          ],
      },
  },
]

Be happy having less spaces and new lines in Your templates!

Advanced usage:

Using modified settings You can: * turn off stripping spaces between HTML tags

TEMPLATE_MINIFIER_HTML_TAGS = False # default = True
  • turn off stripping spaces between Django template tags (s{%, %}s)

TEMPLATE_MINIFIER_TEMPLATE_TAGS = False # default = True
  • turn off all stripping

TEMPLATE_MINIFIER = False # default = True
  • run Your own strip_function, which preprocess templates

TEMPLATE_MINIFER_STRIP_FUNCTION = 'template_minifier.utils.strip_spaces_in_template'

(There is a typo in variable name, see #2 for details)

  • use only in production

if DEBUG:
  TEMPLATE_MINIFIER = False

Known issues:

  • Don’t use // one line comments in Your inline javascript <script> or .js templates. In some cases, if You are using lot of {% if %} there, it can comment out }; or }, for example:

// comment something - !!it's evil!!
{% if %}
function name(){
}
{% endif %}

Use /* */ instead

/* comment something - it's nice and clean <3! */
{% if %}
function name(){
}
{% endif %}

Or just set TEMPLATE_MINIFIER_TEMPLATE_TAGS = False

To do:

  • {% new_line %} template_tag

Metadata

Release files for django-template-minifying-loader 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-template-minifying-loader 1.0
File Size Uploaded
django-template-minifying-loader-1.0.tar.gz 3.8 kB Details

Release files / django-template-minifying-loader-1.0.tar.gz

Download URL django-template-minifying-loader-1.0.tar.gz
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
859fa0e7e9559d16dc591140dde10422582250928c275cc3873c43a8dd880e64
BLAKE2b-256 checksum
How to use checksums
3aeba98478876150f291ad43530d0b7893124c1176d46bf44b082a26a13baa27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.1

1 release file

This release

1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page