Webhelpers and Javascript Minification
Here’s a practical idea which I have in use in a project of mine.
Most of you probably use some javascript library or have some javascript files that you use in your pylons application.
There’s also some talk going on related to javascript files compression, and more recently, minification.
While I’m developing, I like to use the normal(non compressed) javascript files, because it helps on debugging. But for production, using compressed javascript files reduces page load times.
Pylons Webhelpers comes with a useful function to help you include javascript files on your templates, javascript_include_tag.
The idea I had was at first, make that function provide the minified version of the JS file if we’re not running our application in debug mode. If we are on debug mode, server the normal file.
So, I added a minified option to that function above, which does just that.
After a while, I wanted to know how I could minify my own javascript files, and I found out about JSMin. There’s also a python version of it.
That’s when I also thought, hell, I could minify my own javascript files upon request, and even cache that so the routine only runs once.
more ...