prerender/prerender — pull request #68 by lammertw (2014-03-02 22:08:05+00:00)
Title: Feature gzip

This pull request adds the ability to use gzip for caching plugins. It is fully backwards compatible and the gzip functionality is off by default.

It can be enabled by initialising the prerender with options {gzip: true}:

var server = prerender({
workers: process.env.PHANTOM_CLUSTER_NUM_WORKERS,
iterations: process.env.PHANTOM_WORKER_ITERATIONS || 10,
phantomArguments: ["--load-images=false", "--ignore-ssl-errors=true"],
phantomBasePort: process.env.PHANTOM_CLUSTER_BASE_PORT,
messageTimeout: process.env.PHANTOM_CLUSTER_MESSAGE_TIMEOUT
}, {gzip: true});

To opt in on the gzip functionality the plugins can use the new res.sendContent(content) and context.getContent() methods. Which by default do a res.send(200, content) and context.response.documentHTML. However when gzip is enabled is will zip and unzip the content first.

I've seen with gzip that the html content is often only about 10% of the original content. This will speed things up when having to send and retrieve the content to another server and of course save space.