{ "info": { "author": "CobraTeam", "author_email": "andrewsmedina@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Framework :: Django", "Framework :: Django :: 1.11", "Framework :: Django :: 2.0", "Framework :: Django :: 2.1", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Text Processing :: Markup :: HTML" ], "description": "++++++++++++++\ndjango-htmlmin\n++++++++++++++\n\n.. image:: https://secure.travis-ci.org/cobrateam/django-htmlmin.png\n :target: http://travis-ci.org/cobrateam/django-htmlmin\n\ndjango-html is an HTML minifier for Python, with full support for HTML 5. It\nsupports Django, Flask and many other Python web frameworks. It also provides a\ncommand line tool, that can be used for static websites or deployment scripts.\n\nWhy minify HTML code?\n=====================\n\nOne of the important points on client side optimization is to minify HTML. With\nminified HTML code, you reduce the size of the data transferred from the server\nto the client, which results in faster load times.\n\nInstalling\n==========\n\nTo install django-htmlmin, run this on the terminal: :\n\n.. code-block:: sh\n\n $ [sudo] pip install django-htmlmin\n\nUsing the middleware\n====================\n\nAll you need to do is add two middlewares to your ``MIDDLEWARE_CLASSES`` and\nenable the ``HTML_MINIFY`` setting:\n\n.. code-block:: python\n\n MIDDLEWARE_CLASSES = (\n # other middleware classes\n 'htmlmin.middleware.HtmlMinifyMiddleware',\n 'htmlmin.middleware.MarkRequestMiddleware',\n )\n\nNote that if you're using Django's caching middleware,\n``MarkRequestMiddleware`` should go after ``FetchFromCacheMiddleware``, and\n``HtmlMinifyMiddleware`` should go after ``UpdateCacheMiddleware``:\n\n.. code-block:: python\n\n MIDDLEWARE_CLASSES = (\n 'django.middleware.cache.UpdateCacheMiddleware',\n 'htmlmin.middleware.HtmlMinifyMiddleware',\n # other middleware classes\n 'django.middleware.cache.FetchFromCacheMiddleware',\n 'htmlmin.middleware.MarkRequestMiddleware',\n )\n\nYou can optionally specify the ``HTML_MINIFY`` setting:\n\n\n.. code-block:: python\n\n HTML_MINIFY = True\n\nThe default value for the ``HTML_MINIFY`` setting is ``not DEBUG``. You only\nneed to set it to ``True`` if you want to minify your HTML code when ``DEBUG``\nis enabled.\n\nExcluding some URLs\n-------------------\n\nIf you don't want to minify all views in your app and it's under a ``/my_app``\nURL, you can tell the middleware to not minify the response of your views by\nadding a ``EXCLUDE_FROM_MINIFYING`` setting on your settings.py:\n\n.. code-block:: python\n\n EXCLUDE_FROM_MINIFYING = ('^my_app/', '^admin/')\n\nRegex patterns are used for URL exclusion. If you want to exclude all URLs of\nyour app, except a specific view, you can use the decorator\n``@minified_response`` (check the next section above).\n\nKeeping comments\n----------------\n\nThe default behaviour of the middleware is to remove all HTML comments. If you\nwant to keep the comments, set the setting ``KEEP_COMMENTS_ON_MINIFYING``\nto ``True``:\n\n.. code-block:: python\n\n KEEP_COMMENTS_ON_MINIFYING = True\n\nUsing the decorator\n===================\n\ndjango-htmlmin also provides a decorator, that you can use only on views you\nwant to minify the response:\n\n.. code-block:: python\n\n from htmlmin.decorators import minified_response\n\n @minified_response\n def home(request):\n return render_to_response('home.html')\n\nDecorator to avoid response to be minified\n------------------------------------------\n\nYou can use the ``not_minified_response`` decorator on views if you want to\navoid the minification of any specific response, without using the\n``EXCLUDE_FROM_MINIFYING`` setting:\n\n.. code-block:: python\n\n from htmlmin.decorators import not_minified_response\n\n @not_minified_response\n def home(request):\n return render_to_response('home.html')\n\nUsing the ``html_minify`` function\n==================================\n\nIf you are not working with Django, you can invoke the ``html_minify`` function\nmanually:\n\n.. code-block:: python\n\n from htmlmin.minify import html_minify\n html = '
Hello world '\n minified_html = html_minify(html)\n\nHere is an example with a `Flask