﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
18524	Create MinifyHTMLMiddleware	Artem Skoretskiy	nobody	"We need a simple middleware that would compactify all the pages before sending to the client. It should be basically the same as `spaceless` templatetag, but for whole response.

It will reduce page size significantly -- that is important for any production site. Middleware makes sense because you don't have to care about manually using this tag in templates. It makes sense even when you use Gzip as after decompression it needs to be parsed by browser -- so size still matters.

Here is the code. Nothing special, we just use Django internals.
{{{#!python
from django.utils.encoding import DjangoUnicodeDecodeError
from django.utils.html import strip_spaces_between_tags as minify_html

class MinifyHTMLMiddleware(object):
    def process_response(self, request, response):
        if 'text/html' in response['Content-Type']:
            try:
                response.content = minify_html(response.content.strip())
            except DjangoUnicodeDecodeError:
                pass
        return response
}}}

The idea was taken from `django-pipeline`. But since it makes sense and it only uses Django internals -- it would be great to have it in Django itself."	New feature	closed	Core (Other)	dev	Normal	wontfix		tonn81@…	Unreviewed	1	0	0	0	0	0
