minwebhelpers – Welcome to MinificationWebHelpers’s documentation!

Author:Pedro Algarvio <ufs_REMOVE@ME_ufsoft.org>
Maintainer:Domen Kozar <domen_REMOVE@ME_dev.si>
Version:0.3.6
Source:bitbucket.org
Bug tracker:bitbucket.org/issues

Consider the MinificationWebHelpers an extension to WebHelpers.

Basicaly MinificationWebHelpers adds following options to the WebHelpers javascript_link and stylesheet_link functions:

  • minified (bool): Minifies/reduces as much as possible each of the files passed to it’s minimum size to reduce page load times.
  • combined (bool): Joins all files passed into a single one to reduce server requests which in turn reduces page load times.
  • beaker_kwargs (dict): override default arguments that will be passed to beaker_cache.
  • combined_filename (string): Name of the filename that will be used in conjunction with combined=True

For complete list of additional parameters reffer to base_link().

Note

Running Pylons/TG application in debug mode will force minfied and combined options off.

Note

For an up-to-date read of the documentation, always reffer to offical documentation page on site.

Details about implementation

MinificationWebHelpers cache your javascript and css files through Beaker‘s @beaker.cache decorator. Default parameters passed to beaker cache:

beaker_kwargs = dict(key='sources', expire='never', type='memory')

Javascript minification is achieved through Python port of jsmin.

MinificationWebHelpers maps HTTP URLs to filesystem path by exaiming pylons config for static_files.

Usage

On your own Pylons application, inside <app>/lib/helpers.py you add:

from minwebhelpers import *

Then, inside a template you could have:

<head>
  ${ h.javascript_link('/js/file1.js',
                       '/js/file2.js',
                       minified=True,
                       combined=True,
                                                                                               combined_filename='all_javascript_files') }
  ${ h.stylesheet_link('/css/style1.css',
                       '/css/style2.css',
                       minified=True,
                       combined=True,
                       beaker_kwargs=dict(invalidate_on_startup=False)) }
</head>

The above would mean file1.js and file2.js would be combined and then minimized (same story for css files).

Instalation

It’s as easy as:

sudo easy_install MinificationWebHelpers

Or if you wish to install current trunk:

sudo easy_install http://bitbucket.org/iElectric/minificationwebhelpers/get/tip.zip

API

Indices and tables