diff --git a/README.rst b/README.rst index f1d99d5e..fa686b91 100644 --- a/README.rst +++ b/README.rst @@ -64,6 +64,16 @@ The default value for the ``HTML_MINIFY`` setting is ``not DEBUG``. You only need to set it to ``True`` if you want to minify your HTML code when ``DEBUG`` is enabled. +You can also optionally specify the ``HTML_MINIFY_AJAX`` setting: + + +.. code-block:: python + + HTML_MINIFY_AJAX = False + +The default value for the ``HTML_MINIFY_AJAX`` setting is ``True``. You only +need to set it to ``False`` if don't want to minify AJAX requests. + Excluding some URLs ------------------- diff --git a/htmlmin/middleware.py b/htmlmin/middleware.py index 00eeaee5..01b37f51 100644 --- a/htmlmin/middleware.py +++ b/htmlmin/middleware.py @@ -50,6 +50,9 @@ def can_minify_response(self, request, response): if regex.match(request.path.lstrip('/')): req_ok = False break + + if not getattr(settings, 'HTML_MINIFY_AJAX', True) and request.is_ajax(): + return False resp_ok = 'text/html' in response.get('Content-Type', '') if hasattr(response, 'minify_response'):