{"id":16653717,"url":"https://github.com/baseplate-admin/django_strip_whitespace","last_synced_at":"2025-04-09T18:11:03.006Z","repository":{"id":45199883,"uuid":"430274823","full_name":"baseplate-admin/django_strip_whitespace","owner":"baseplate-admin","description":"A Powerful HTML white space remover for Django","archived":false,"fork":false,"pushed_at":"2022-01-01T04:34:57.000Z","size":63,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-22T22:18:03.207Z","etag":null,"topics":["alpinejs","django","middleware"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/django-strip-whitespace/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/baseplate-admin.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-21T04:42:56.000Z","updated_at":"2023-03-28T03:50:36.000Z","dependencies_parsed_at":"2022-09-18T04:21:28.742Z","dependency_job_id":null,"html_url":"https://github.com/baseplate-admin/django_strip_whitespace","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baseplate-admin%2Fdjango_strip_whitespace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baseplate-admin%2Fdjango_strip_whitespace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baseplate-admin%2Fdjango_strip_whitespace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/baseplate-admin%2Fdjango_strip_whitespace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/baseplate-admin","download_url":"https://codeload.github.com/baseplate-admin/django_strip_whitespace/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248085213,"owners_count":21045137,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alpinejs","django","middleware"],"created_at":"2024-10-12T09:46:55.263Z","updated_at":"2025-04-09T18:11:02.985Z","avatar_url":"https://github.com/baseplate-admin.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"HTML Whitespace remover for Django\n==================================\n|Pepy.tech Badge| |PyPi Version Badge| |Python Versions Badge| |License Badge| |Code Style| |Lines of Code Badge| \n\n.. |Pepy.tech Badge| image:: https://static.pepy.tech/personalized-badge/django-strip-whitespace?period=total\u0026units=international_system\u0026left_color=grey\u0026right_color=orange\u0026left_text=Downloads\n   :target: https://pepy.tech/project/django-strip-whitespace\n\n.. |PyPi Version Badge| image:: https://badge.fury.io/py/django-strip-whitespace.svg\n    :target: https://badge.fury.io/py/django-strip-whitespace\n\n.. |Python Versions Badge| image:: https://img.shields.io/pypi/pyversions/django-strip-whitespace\n    :alt: PyPI - Python Version\n    :target: https://github.com/baseplate-admin/django_strip_whitespace/blob/main/setup.py\n\n.. |License Badge| image:: https://img.shields.io/pypi/l/django-strip-whitespace\n   :alt: PyPI - License\n   :target: https://github.com/baseplate-admin/django_strip_whitespace/blob/main/LICENSE\n   \n.. |Code Style| image:: https://img.shields.io/badge/code%20style-black-000000.svg\n   :alt: Code Style\n\n.. |Lines of Code Badge| image:: https://tokei.rs/b1/github/baseplate-admin/django_strip_whitespace\n   :alt: Lines of Code\n   :target: https://github.com/baseplate-admin/django_strip_whitespace\n   \nIntroduction :\n--------------\nA powerful tool to optimize Django rendered templates\n\nWhy use \"django_stip_whitespace\" ?\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n*   Adds line break to InlineJS.\n*   It can automagically minify inline CSS, JS.\n*   Removes \u003c!--prettier-ignore--\u003e from HTML.\n*   It compiles regex at runtime. So it's blazing fast.\n*   It speeds up website by reducing the HTML size.\n*   Drop in replacement for 'django.gzip.GzipMiddleware'.\n*   Its mostly based on C ( gzip ) and Rust ( `minify-html \u003chttps://pypi.org/project/minify-html/\u003e`_  ) libraries.\n*   Significantly lower bytes transferred when working with frameworks like AlpineJs ( Almost fully working \u0026 Please open a issue in the `Issue Tracker \u003chttps://github.com/baseplate-admin/django_strip_whitespace/issues\u003e`__ if you encounter any bug) \u0026 Petite Vue.\n*   Is very customizable. ( You can configure lower level `minify-html \u003chttps://github.com/wilsonzlin/minify-html/blob/master/python/src/lib.template.rs/\u003e`_ rust bindings and also the lower level `python \u003chttps://github.com/juancarlospaco/css-html-js-minify/blob/master/css_html_js_minify/html_minifier.py/\u003e`_ bindings from settings.py )\n\n\nWhy shouldn't you use \"django_stip_whitespace\" ?\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n*   You don't like having unnecessary ';;' in your HTML. ( If you know any regex to fix this please put a pull request )\n\n*   Although I tried my best to use Compiled Language for Optimizations. It can still be sub miliseconds ( \u003e 0.001 ) slower compared to normal Django Rendering. ( If you know any way to improve performance, please put a pull request )\n\n\nRequirements :\n--------------\n\n*    `python-strip-whitespace \u003chttps://github.com/baseplate-admin/python_strip_whitespace\u003e`_\n*    Django \u003e 3 ( Should work with version 2? )\n*    Python 3 ( Should work with all version? )\n*    Brotli ( or BrotliPy ) | ( Optional )\n*    ZSTD ( Optional ) \n\nUser guide :\n============\n\nInstallation :\n--------------\n\nInstall with pip from pypi (No extra dependencies):\n\n.. code-block:: python\n\n      $ python -m pip install django_strip_whitespace\n\nInstall with pip with Brotli support:\n\n.. code-block:: python\n\n      $ python -m pip install django_strip_whitespace[brotli]\n\nSame but with Zstandard support:\n\n.. code-block:: python\n\n      $ python -m pip install django_strip_whitespace[zstd]\n\n\n\n\nInstall with pip from github ( Development | Not Recommended for Production )::\n    \n      $ python -m pip install https://codeload.github.com/baseplate-admin/django_strip_whitespace/zip/refs/heads/main\n\n\nThen include it in your django project:\n   \n.. code-block:: python\n\n    MIDDLEWARE = [\n        ...\n        \"strip_whitespace.middlewares.HtmlStripWhiteSpaceMiddleware.html_strip_whitespace\",\n    ]\n\nOr if you like:\n   \n.. code-block:: python\n\n    MIDDLEWARE += \"strip_whitespace.middlewares.HtmlStripWhiteSpaceMiddleware.html_strip_whitespace\"\n\nCustomization :\n===============\n\nChange Lower Level Bindings :\n-----------------------------\n\nRust :\n~~~~~~\n\nThe module allows `rust \u003chttps://github.com/wilsonzlin/minify-html\u003e`_ minifier options to be changed from Django's settings.py file. If you would like to change any settings, refer to `minify-html's \u003chttps://github.com/wilsonzlin/minify-html/blob/master/python/src/lib.template.rs/\u003e`_ source code.\n\n\nThe bindings are ( by default set to True ):\n\n.. code-block:: python\n\n    STRIP_WHITESPACE_RUST_DO_NOT_MINIFY_DOCTYPE, # passes do_not_minify_doctype to minify-html\n    STRIP_WHITESPACE_RUST_ENSURE_SPEC_CONPLIANT_UNQUOTED_ATTRIBUTE_VALUES, # passes ensure_spec_compliant_unquoted_attribute_values to minify-html\n    STRIP_WHITESPACE_RUST_KEEP_CLOSING_TAGS, # passes keep_closing_tags to minify-html\n    STRIP_WHITESPACE_RUST_KEEP_COMMENTS, # passes keep_comments to minify-html\n    STRIP_WHITESPACE_RUST_KEEP_HTML_AND_HEAD_OPENING_TAGS, # passes keep_html_and_head_opening_tags to minify-html\n    STRIP_WHITESPACE_RUST_KEEP_SPACES_BETWEEN_ATTRIBUTES, # passes keep_spaces_between_attributes to minify-html\n    STRIP_WHITESPACE_RUST_MINIFY_CSS, # passes minify_css to minify-html\n    STRIP_WHITESPACE_RUST_MINIFY_JS, # passes minify_js to minify-html\n    STRIP_WHITESPACE_RUST_REMOVE_BANGS, # passes remove_bangs to minify-html\n    STRIP_WHITESPACE_RUST_REMOVE_PROCESSING_INSTRUCTIONS, # passes remove_processing_instructions to minify-html\n\nIf you would like to change any of the above variables, simply put them in settings.py ( Please note that every variable here is a python boolean ).\n\nFor example:\n\n.. code-block:: python\n\n    # settings.py\n\n    STRIP_WHITESPACE_RUST_DO_NOT_MINIFY_DOCTYPE = False\n\nPython :\n~~~~~~~~\n\nThe module allows python minifier options to be changed from Django's settings.py file. If you would like to change any settings, refer to `python-module's \u003chttps://github.com/juancarlospaco/css-html-js-minify/blob/master/css_html_js_minify/html_minifier.py/\u003e`_ source code.\n\nThe bindings are ( by default set to a sane value ):\n\n.. code-block:: python\n\n    STRIP_WHITESPACE_PYTHON_REMOVE_COMMENTS, # False | removes comments from HTML using python ( not recommended cause rust can do that just fine and fast )\n    STRIP_WHITESPACE_PYTHON_CONDENSE_STYLE_FROM_HTML, # True | replaces '\u003cstyle text/css\u003e' -\u003e '\u003cstyle\u003e'\n    STRIP_WHITESPACE_PYTHON_CONDENSE_SCRIPT_FROM_HTML, # True | replaces '\u003cscript text/javascript\u003e' -\u003e '\u003cscript\u003e'\n    STRIP_WHITESPACE_PYTHON_CLEAN_UNNEEDED_HTML_TAGS, # True | removes some unnecessary tags\n    STRIP_WHITESPACE_PYTHON_CONDENSE_HTML_WHITESPACE, # True | This is where the magic happens.\n    STRIP_WHITESPACE_PYTHON_UNQUOTE_HTML_ATTRIBUTES, # True | This is also a magic module.\n\n\nIf you would like to change any of the above variables, simply put them in settings.py ( Please note that every variable here is a python boolean )\n\nFor example:\n\n.. code-block:: python\n\n    # settings.py\n\n    STRIP_WHITESPACE_PYTHON_REMOVE_COMMENTS = True \n\nChange Ignored Paths :\n----------------------\n\nThis module allows dynamic ignored path allocation.\nSo for example if your sitemap.xml is at url '/sitemap.xml' and you want to avoid minifying it ( Because this module in lower level is meant to minify HTML not XML ).\nThen you can add it to ignored path. ( By default it ignores '/sitemap.xml' ) \n\nTo customize ignored path:\n\n.. code-block:: python\n\n    # settings.py\n\n    STRIP_WHITESPACE_MINIFY_IGNORED_PATHS.append(\"/robots.txt\") # Note that STRIP_WHITESPACE_MINIFY_IGNORED_PATHS is a Python List\n\nChange NBSP Mangle Character :\n------------------------------\n\nThis module first replaces the \u0026nbsp; character from html with a character. \nFor example \u0026nbsp; becomes 'অ' ( I picked 'অ' because its a foreign character and not many sites use the character like this 'অ' ).\nIf for some reason this character is causing problem in your HTML. You can change this from settings.py .\n\nTo change \u0026nbsp; mangle character:\n\n.. code-block:: python\n\n    # settings.py\n\n    # Keep the string as  short as possible.\n    # If you make it long,\n    # the python str.replace() method will use more CPU and RAM thus slowing your site down.\n\n    STRIP_WHITESPACE_NBSP_MANGLE_CHARACTER = 'ga' # Note that STRIP_WHITESPACE_NBSP_MANGLE_CHARACTER is a python string\n\nChange Compression Settings :\n-----------------------------\nThis module can do the work of django.gzip middleware. ( It can also do brotli, zstd 👀 )\n\nTo change the compression algorithm ( by default using 'gzip' because it's a python stdlib): \n\n.. code-block:: python\n\n  # settings.py\n  STRIP_WHITESPACE_COMPRESSION_ALGORITHM = \"gzip\" or \"br\" or \"zstd\" or \"plain\"\n\n\nTo use this module with django.gzip middleware ( or `django_brotli \u003chttps://github.com/illagrenan/django-brotli\u003e`_ middleware ):\n\n.. code-block:: python\n\n  # settings.py\n  STRIP_WHITESPACE_COMPRESSION_TYPE = 'compressed'\n\n\nContributing :\n==============\nIf you like this project add a star. \nIf you have problems or suggestions please put them in the `Issue Tracker \u003chttps://github.com/baseplate-admin/django_strip_whitespace/issues\u003e`__.\nIf you like to add features. Fork this repo and submit a Pull Request. 😛\n\nUpdates ?? :\n============\nThis repository is freezed. It will automatically install latest `python-strip-whitespace \u003chttps://github.com/baseplate-admin/python_strip_whitespace\u003e`_\n\nSpecial Thanks to :\n===================\n*    `alfonsrv \u003chttps://github.com/alfonsrv\u003e`_ : For making me `realize \u003chttps://www.reddit.com/r/django/comments/qyqxht/comment/hlj3rzb/?utm_source=share\u0026utm_medium=web2x\u0026context=3\u003e`_ that this module can be used without django gzip middleware\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaseplate-admin%2Fdjango_strip_whitespace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbaseplate-admin%2Fdjango_strip_whitespace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbaseplate-admin%2Fdjango_strip_whitespace/lists"}