views:

237

answers:

4

Hi,

I have following case: I want to use uncompressed js/css files during development (to debug js for example) but on production I want to switch automatically to minified versions of that files.

some simple solution is to put in your template:

<script src="some_js.{% if not debug %}min.{% endif %}js"....

but this require manully providing that such file exist and to do minifaction manullay after original file change.

How do you accomplish this in your projects? Is there any tool for this?

+3  A: 

Did you try http://code.google.com/p/django-compress/ ?

Pierre-Jean Coudert
Perfect! Thanks a lot!
Lukasz Dziedzia
A: 

With Visual Studio use Post-build Events (accessible under the project's properties). I'm sure other IDEs have similar options. Just wire your compiler/minifier to drop the file off in the appropriate location for run-time, and change your file in the project to not deploy on a build.

Lance May
+3  A: 

I've been using django-assets and so far I'm very satisfied. What I really like about it, is that you're still able to define your CSS and JS files inside of your templates, instead of in the project configuration.

Documentation can be found at: http://elsdoerfer.name/docs/django-assets/

heyman
A: 

I wrote this Makefile to minify and concatenate my JS and CSS files. It depends on the YUI Compressor JAR. After updating a file, you still have to run make though. Nevertheless, you can make it run when the server starts and/or reloads, or setup a commit-hook on your SCM.

Of course you still need the {% if not debug %}, but it's a small price to pay IMO.

Showing the simple usage:

$ make
[css] static/css/first.css
[css] static/css/second.css
[css] static/css/third.css
[css] static/css/and_so_on.css
[tag] @import url("static/css/all.css");
[js] static/js/first.js
[js] static/js/second.js
[js] static/js/third.js
[js] static/js/and_so_on.js
[tag] <script type="text/javascript" src="static/js/all.js"></script>
Done.
jweyrich