Search code examples
pythondjangocompressiongzipstatic-files

Can I gzip JavaScript and CSS files in Django?


I tried profiling my web application and one of the bottlenecks reported was the lack of gzip compression. I proceeded to install the gzip middleware in Django and got a bit of a boost but a new report shows that it is only gzipping the HTML files i.e. any content processed by Django. Is there a way I could kludge/hack/force/make the middleware gzip my CSS and my JS as well?

Could someone please answer my questions below. I've gotten a little lost with this.

  • I might have gotten it wrong but people do gzip the CSS and the JS, don't they?
  • Does Django not compress JS and CSS for some browser compatibility issues?
  • Is compressing and minifying the same thing?

Thanks.


Solution

  • Thanks everyone.

    It seems that the GzipMiddleware in Django DOES compress CSS and JS.

    I was using Google's Page Speed plugin for Firebug to profile my page and it seems that it was generating reports based on old copies (non-gzipped versions) of the CSSs and JSs in my local cache. These copies were there from the time before I enabled the Gzip middleware. I flushed the cache and it seems that the reports showed different results altogether.