RobeeeJay edited this page Oct 23, 2012 · 4 revisions

This module compresses and serves static css content which requires compressing by the Less compiler. It serves the compressed files using the Lactate node module.

new fw.CompressorLess({ staticDir: "/static", expireTime: "two days", cacheMem: true,
   updateInterval: 5000, extUncompressed: ".less", extCompressed: ".css", compressCss: true });

All arguments apart from staticDir are optional.

updateInterval is the time period between checks that a less file has been changed.

extUncompressed is the extension for uncompressed files, defaults to ".less".

extCompressed is the extension for compressed files, defaults to ".css".

compressCss specifies if the resulting compiled css should be compressed as well. Defaults to true, but useful to set it to false during debugging.

headers is an object containing key/value pairs which represent any custom headers you would like to set, like for example { "Content-Type": "text/css; charset=utf-8" }

staticDir should point to the root directory which contains your static content. expireTime is the cache time for the content, see the Lactate documentation for more details. cacheMem (enabled by default) is whether files should be cached to reduce disk access.

Simple Example

var stackFull = new fw.Stack();

stackFull.append(new fw.CompressorLess({ staticDir: __dirname + "/static" }));

If the request.url is "/styles/dog.css" and the file "./static/styles/dog.less" exists, this will compress that file into dog.css. If no such Less file exists, it will try to serve dog.css. If that doesn't exist, it will continue to the next entry in the Stack.