Take a quick tour!

Compressing CSS and Javascript in Django

Article Archive

-  2011 (3)
+  2010 (41)
+  2009 (15)
+  2008 (15)

Experience Our Products

Education & Inspiration

Testimonials

" My partner and I are very happy with the transition to the Dashboard for my website. I deleted most of the old photos last night, and add new photos that I took yesterday afternoon. We were amazed that it was so easy. . . we're both very pleased with the results. Thanks again for all of your work with us to upgrade! So worth the money and time!" - X. B.

read more...

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

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.

 


Category: Web Design


Comments

  • No one has commented yet.