Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: auto minifying css/js files before release

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?

like image 984
dzida Avatar asked Jun 17 '10 14:06

dzida


People also ask

Why should you minify your JavaScript scripts before publishing them?

These characters include whitespaces, line breaks, comments, and block delimiters which are useful for us humans but unnecessary for machines. We minify the files of a website containing CSS, HTML, and Javascript code so your web browser can read them faster.

Should I minify CSS and JS?

It is important to minify your CSS and minimise JavaScript files so they can load faster on your web pages. There are many reasons why you should minify your CSS and JavaScript: Reduce file size: The more code there is in a file, the larger it will be. Minified code is usually much smaller than the original version.

Is Minified CSS faster?

It loads usually faster because minified CSS/JS file is simply smaller in size, so it takes less to download and process.


1 Answers

Did you try django-compress ?

See http://djangopackages.com/grids/g/asset-managers/ for a fairly complete list of available asset managers for Django...

If you already are using django-compress, you should have a look at upgrading to django-pipeline, which is a well maintained fork, with a lot of new features. I encourage everyone to who is using django-compress to switch to django-pipeline instead: * django-pipeline documentation

like image 69
Pierre-Jean Coudert Avatar answered Sep 30 '22 18:09

Pierre-Jean Coudert