Small and Crunchy

.:[ Small and Crunchy :: Minifying Asset Server ]:.

Download as .zip Download as .tar.gz View on GitHub

Small and Crunchy

SaC is a tiny service to take big things and make them small. It accepts requests for minified CSS or JS files, expects to find non-minified copies on-disk, and serves up the minified one you asked it for.

Installation

npm install -g sac

Usage

sac

Seriously, that's it (unless you need to change the defaults, see the section on "Configuration").

SaC will launch, check the number of cores on your system, and spawn a minion for each core. It will then listen on port 40480 and accept requests for any resource ending in .min.js, or .min.css. When it gets a request, it will find the unminified file version, and respond with a minified copy.

Example

Assuming default configuration...

curl http://localhost:40480/scripts/jquery.min.js

SaC looks for jquery.js at /data/www/docroot/scripts/jquery.js

If it exists, /usr/bin/r.js is called and the result is returned in the response body with a 200 status in the header. Content-Type is set to either application/javascript or text/css, depending on the content.

HTTP Status Codes

SaC will return reasonably sane HTTP status codes with most responses.

Configuration

SaC has some (not many) configurable options, mostly to accomodate systems that don't line up with the defaults. These are all passed in as runtime arguments.

docroot (default: /data/www/docroot)

This is where SaC expects to find the canonical assets.

sac --docroot </path/to/docroot>

port (default: 40480)

The port SaC will listen on for connections (a web-accessible status page can be found at (port + 1)).

Attempting to bind to a port below 1024 will require root, and is generally advised against.

sac --port <1025-65534>

requirejs (default: /usr/bin/r.js)

Since SaC uses requirejs to minify content, it needs to know where to find it. This may vary by operating system and configuration.

If you're not sure where to find it, you can check with 'which r.js'.

sac --requirejs /usr/local/bin/r.js