How minification works
- removing characters (like whitespaces and tabs) the processor/interpreter is insensitive to
- replacing long variable names with shorter ones (eg: naming variables with just one or two letters)
This is helpful as it decreases the size of
.js files and therefore when these files will be sent over the wire they'll take less time (and bandwidth) to be delivered.
A shortcoming is that minified code is no longer readable by humans, but this seldom is a problem as minification is a one-way process and one can automate it in order to keep the unminified source files apart.
You can read in my previous post how to setup a weblog using the Pelican library.
In order to install the dependencies we'll need, you need to install the
pip package manager
I've looked specifically for Python minifiers and found
csscompressor for CSS minification.
You can install them with:
$> pip install jsmin $> pip install csscompressor
Their usage is very simple:
The minifiers output shall be put into your blog's css and js folders, getting served by your webserver.
You can (and you should) add the resource minification commands to your automatic blog-build script - and if you don't have one, go make it! ;)