--- author: '' category: '' date: 2012/08/10 20:06:54 description: '' link: '' priority: '' slug: nikola-filters-bundles tags: nikola, python title: 'Nikola: Filters & Bundles' type: text updated: 2012/08/10 20:06:54 url_type: '' --- Two upcoming features for the next release of `Nikola `_, my static site generator, due sometime in August. Filters ------- Filters let you postprocess your output. Think of it like instagram for websites, but useful. You can configure per file extension a series of python functions or shell commands, which will be applied in place to the output file. For example, suppose you want to apply yui-compressor to your CSS and JS files: .. code-block:: python FILTERS = { ".css": [filters.yui_compressor], ".js": [filters.yui_compressor], } There, ``filters.yui_compressor`` is a simple wrapper around the command so that it applies in-place to the output files. If you use strings there (untested), they are taken as commands. The "%s" will be replaced by the filename, the usual crazy shell quoting rules apply: .. code-block:: python FILTERS = { ".jpg": ["jpegoptim '%s'"], ".png": ["pngoptim '%s'"], } Keep in mind that the filters modify the *output* of Nikola, not the input, so your images, CSS, and JS files will not be touched in any way. And of course changing the filters applied to a file will force a rebuild, so you can experiment freely. Bundles ------- Having many separate CSS or JS files is usually a nono for performance reasons because each one may involve a separate HTTP transaction. The solution is to "bundle" those files in a single, larger file. The reason not to do that is that usually it means having a huge, uncomfortable thing to handle. So Nikola tries to give you the best of both worlds, by letting you have separate files, and bundling them (or not) on build. There is a new option, ``USE_BUNDLES`` that defaults to False, and there are some changes in the theme templates so that it uses the bundled version when needed. This was only possible thanks to `Webassets `_. However, if you don't have Webassets installed, or you don't enable USE_BUNDLES, this should cause no changes in the output. Conclusion ---------- These new features will allow Nikola users to improve their site's performance with minimal tweaking, which is always a good thing.