URL: http://pypi.python.org/pypi/django-static/1.5.0

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";
body{background-image:url(/images/foo.1257701686.png)}

# bar.css
div.content{background-image:url("/css/bar.1257701552.png")}

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.

Comments

navisrob

Note that you can also use alternative standard Django static storage: https://maketips.net/tip/27/django-static-versioning . Looks like it is simpler way now.

Your email will never ever be published.

Previous:
RequireJS versus HeadJS January 9, 2011 JavaScript
Next:
Fastest "boolean SQL queries" possible with Django January 14, 2011 Django
Related by category:
How to avoid a count query in Django if you can February 14, 2024 Django
How to have default/initial values in a Django form that is bound and rendered January 10, 2020 Django
My site's now NextJS - And I (almost) regret it already December 17, 2021 Django
How to sort case insensitively with empty strings last in Django April 3, 2022 Django
Related by keyword:
Local Django development with Nginx October 11, 2010 Django
Hosting Django static images with Amazon Cloudfront (CDN) using django-static July 9, 2010 Django
The awesomest way possible to serve your static stuff in Django with Nginx March 24, 2010 Django
premailer now with 100% test coverage August 22, 2014 Python