django-static version 1.5 automatically taking care of imported CSS

11 January 2011   0 comments   Django

Powered by Fusion×

I just released django-static 1.5 (github page) which takes care of optimizing imported CSS files.

To explain, suppose you have a file called foo.css and do this in your Django template:

{% load django_static %}
<link href="{% slimfile "/css/foo.css" %}"
  rel="stylesheet" type="text/css" />

And in foo.css you have the following:

@import "bar.css";
body {
   background-image: url(/images/foo.png);

And in bar.css you have this:

div.content {
   background-image: url("bar.png");

The outcome is the following:

# foo.css
@import "/css/bar.1257701299.css";

# bar.css

In other words not only does it parse your CSS content and gives images unique names you can set aggressive caching headers on, it will also unfold imported CSS files and optimize them too.

I think that's really useful. You with one single setting (settings.DJANGO_STATIC=True) you can get all your static resources massaged and prepare for the best possible HTTP optimization. Also, it's all automated so you never need to run any build scripts and the definition of what static resources to use (and how to optimize them) is all defined in the template. This I think makes a lot more sense than maintaining static resources in a config file.

The coverage is 93% and there is an example app to look at in the if you prefer that over a README.


Your email will never ever be published

Related posts

RequireJS versus HeadJS 09 January 2011
Fastest "boolean SQL queries" possible with Django 14 January 2011
Related by keywords:
The awesomest way possible to serve your static stuff in Django with Nginx 24 March 2010
Hosting Django static images with Amazon Cloudfront (CDN) using django-static 09 July 2010
Local Django development with Nginx 11 October 2010
premailer now with 100% test coverage 22 August 2014
Gamification for me as a software developer 21 December 2012