I know that it’s better to use something like AWS for static files but I am on developing stage and I prefer to have javascript/css files on localhost.
It would be great if I could get gzip working on my javascript files for testing. I am using the default gzip middleware but it’s just compressing the view request.
My template looks like:
<script src='file.js' type='application/javascript'></script>
There should be a type-of-file list similar to Nginx for the django-based-server. How can I add application/javascript, text/javascript, etc for gzip compression?
You should read the GZipMiddleware documentation, where it’s explained that the middleware will not compress responses when the “Content-Type header contains javascript or starts with anything other than text/”.
EDIT:
To clarify what the documentation says, if the
Content-Typeheader value containsjavascriptor doesn’t begin withtext/, then the response won’t be compressed. That means bothtext/javascriptandapplication/javascriptwill be invalid responses, since they matchjavascript.Those restrictions are intentionally imposed by the middleware itself, but you can still circumvent that by wrapping the static files view handler with the
gzip_page()decorator and adding it to your URL configuration manually.