Looking for a python library that handles minifying and merging JS\CSS files together...
-
http://mail.python.org/pipermail/python-list/2009-March/1195436.html I doubt much changed since then, but would also like to hear answer – Daniel Kluev Aug 03 '10 at 18:48
-
Hello? Are you on vacation? It generally helps get you the answer you're looking for if you tell existing respondents what's wrong with their answers. – ssokolow Sep 20 '10 at 07:48
3 Answers
As anurag said, Django users can use django-compress.
If you're using Pylons or TurboGears 2.x, there are two real-time options:
- MinificationWebHelpers (Realtime minification helpers for CSS/JS which support using Beaker to cache the output)
- Minimatic (A fork of MinificationWebHelpers. Some users swear by it but, according to the author of MinificationWebHelpers, the devs are unwilling to cooperate with upstream to merge changes)
To the best of my knowledge, the realtime options for Django and Pylons only do minification and concatenation. They don't parse the Javascript to implement any kind of import/include directive.
If you prefer a batch option, I can't think of anything written specifically in Python, but these are the options I've seen other Python developers using:
- Write a Python or shell script that runs a low-level tool like YUI Compressor (Java) or jsmin.py and does any concatenation it doesn't do for you. (One of my projects does this. It doesn't give you import/include directives, but it does get the job done with minimal dependencies.)
- RequireJS Optimize (A minification and import-management tool for JS/CSS bundling. Written in Java.)
- Juicer used with RequireJS (Requires Ruby and uses JavaDoc-style import declarations in addition to RequireJS calls, but makes the Java dependency (for YUI Compressor) optional.)
- Ender.js or Jam (Both written in Node.js)
If a pure Python solution is really important, my advice is to either go with the realtime options (easier for development with things like paster --reload
) or write a command for setup.py or paster which uses jsmin.py and cssmin to do the heavy lifting.
Note: Due to a lack of documentation, the setup.py link points to one of my blog posts.
This SO answer may also be useful: Python script for minifying CSS?
Check this simple python script.
http://github.com/hkasera/minify
It minifies js as well as css files too. It even stores detailed log files illustrating the errors and warnings during the process.
Hope it may help!

- 2,118
- 3
- 23
- 32