cobrateam/django-htmlmin — pull request #64 by moeffju (2013-11-28 16:29:44+00:00)
Title: Split middleware into two parts to work around Django’s ordering issues

Django only has one stack for both request and response middlewares and goes through them in top-down on request, bottom-up on response. So we need to split the middleware up if we want to use proper caching: Mark the request as uncached on the way “down”, and only minify on the way back up if the request was marked.

```
REQUEST RESPONSE

| ^ <- UpdateCache (towards the end of the
| | response phase)
FetchFromCache | | <- HtmlMinify (before the cache is updated)
(req ends here | |
if cache hit) -> | |
| |
MarkRequest -> V |
___________________
[ Application ]
```