Package: shrink
ShrinkShrink is a command for concatenating and compressing css stylesheets and
javascript files making them smaller.
Shrinking (or minifying) these files reduces the number of request that are
made after a page load and also the size of these requests.This command depends onYUI Compressorfor compression, and runs with
Python 2.5 and above, including Python 3.InstallShrink can be easily installed from pypi by running:$ pip install shrinkAfter install is good to display script information and options:$ shrink -hConfig fileINIstyle files are used to know which files will be minified, set some
global options and also to know which files will be joined before
minification.A good starting point to get familiar with Shrink config file format is to
read the example shrink config file. To create an example file run:$ shrink --example-cfgThis command creates a file calledexample_shrink.cfgin current folder.Config file formatConfig file has a section for each individual file that can be generated,
and on top it also has a special section calledDEFAULTwhere global
options are defined.GlobalDEFAULToptions:base_dirdefines a base directory used as prefix to find static files.
This value can be referenced in any other section using the python variable
notation%(base_dir)s.hash_dirdefines a folder whereshrink.sha1file is stored. SeeShrink hash filefor more info. By default, this file is stored in the
same folder where shrink config file is located.arg.*defines default values for some command line argumens. Supported
arguments arearg.java_binandarg.yui_jar.
The values given here are overriden by the ones given during runtime as
command line arguments.Each file section has some options that are used during join, compression and
hashing of a file. These file section options are:source_directoryvalue defines the folder where file(s) listed insource_filesare located.source_filesvalue can be a single file name, or a list of file names.
When a list of names is given, each file in list is concatenated (from top
to down) into a single file before compression.destination_directoryvalue sets output directory for the minified file
By default minified file is generated in source directory.destination_filevalue is the name for the minified file.hashis a boolean value. When it is true destination file is included
during shrink hash generation. SeeShrink hash file.compressis a boolean value. Destination file is not compressed when
this value is false. By default compression is done for destination
files.
This option is useful when is desirable to join many files without
compressing them because they are already compressed.For example, a section for minifying a file calledsample-file.jscould
be written as:[sample-single-file-js]
source_directory = %(base_dir)s/js
destination_file = sample-file.min.js
source_files = sample-file.jsFinal minified file name would besample-file.min.js.Many files can also be specified to be joined into a single file before
compression by writing a section like:[sample-multiple-file-css]
source_directory = %(base_dir)s/css
destination_file = sample-multiple-file.min.css
source_files =
    sample-file1.css
    sample-file2.css
    sample-file3.cssGenerated file name is given bydestination_filevalue.Minimize css and js filesTo minify all files, run:$ shrink -f example_shrink.cfg allThis will useyuicompressor.jarand theexample_shrink.cfgfile in
current directory to compress all files.In case that minification is not desired for all files, is also possible to
minify individual files, or a group of files (SeeSection groups), by
using the name(s) of each section instead ofallas argument.To list available sections, run:$ shrink -f example_shrink.cfg -lSection groupsInstead of running script withsample-single-file-jsandsample-multiple-file-cssas arguments is possible to define a group like:[sample-group]
group =
    sample-single-file-js
    sample-multiple-file-cssAnd then run minifier script withsample-groupas the only parameter.Shrink hash fileAfter minification Shrink can create a file containing a SHA1 hash. The file
is created when at least one section in config file hashash = true. Hash
is created using the contents of all destination files in these sections.This is useful to know when some files changed, and to reload static css and
javascript files without using a timestamp or version number.
Sometime can be desirable to reload modified static files without increasing
application version. In these cases the hash can be used as request parameter
instead of version number.Deployment notesIt can happen your application stop working or have unespected results when
it is deployed with minified css and javascript files.
Many times some of these problems are is easy avoid by having present the
following notes duringshrink.cfgsetup:The order of the source files in each config section must be the same as
the one in your HTML templates.CSS files normally contains URLs which are relative to the location of
the file where they are declared. So for these cases the location for
destination file must be the same as the one for source files.
Some javascript files might define some path or URL that might also be
relative to a file location.Check that all files wich are NOT minified are being included in your
HTML template.Changelog1.1.1 - 2012-09-21Setup argument use_2to3 is now enabled only for python 3 seriesAddedDeployment notesto README fileAdded read permissions to generated files for group and others1.1.0 - 2012-07-31Added python 3 supportUpdated documentationAdded initial files for unit testing1.0.1 - 2012-07-19Added –hash-dir argument to allow changing hash file dir during runtimeAddedcompressINI file option to avoid compressing destination fileAdded –example-cfg argument to create an example_shrink.cfg file in
current folder1.0.0 - 2012-07-11Added –version argumentAdded SHA1 hashing support (hash = truein any file section)Added –hash-all argument to generae SHA1 hash using all files contents