Compressing CSS and Javascript in Django
Posted by administrator on Tuesday, February 15th, 2011
As Django developers, we often spend some time researching great projects that help our client's websites. Today we stumbled across a neat project.
Django CSS is a CSS and JavaScript minifier and compressor. It's very easy to use. This is an example of how it works:
{% load compress %}
{% compress css %}
<link rel="stylesheet" href="/media/css/one.css" type="text/css" charset="utf-8">
<link rel="stylesheet" href="/media/css/two.sass" type="text/css" charset="utf-8">
{% endcompress %}
Which would be rendered like:
<link rel="stylesheet" href="/media/CACHE/css/f7c661b7a124.css" type="text/css" media="all" charset="utf-8">
You can specify a CSS compressor engine (an executable program on the server) in the site's settings.py. It is also smart to detect if you have DEBUG on. If so, it doesn't compress and cache your minified CSS and JavaScript.
The compressor can also compress inline styles and rewrite it as an external css file.
Comments
- No one has commented yet.


