Django Compress: New CSS Filter
March 23, 2009
I had a specific use case for the new filter: my css had a lot of root relative urls for background images. I wanted to host my compiled media on a different host than where my images were being hosted from but this tied the two together.
Furthermore, I didn't want to hard code the absolute urls as I want to be able to test the full environment on my laptop, test environments and finally be able to deploy somewhere else in production. I want the process of changing environments to be simple settings file change.
Therefore, my approach was to create a filter that at compile time execute a string find and replace. It's super simple, but useful, at least to me.
I also found what I think were a couple of bugs when you had some groups with
external_urls defined. When they were missing
output_filenames definitions, exceptions were raised when running the
management command to compile the source. I put some simple checks in place to
safe guard against these exceptions.