HttpStripModule

= mod_strip =

''Note: this module is not distributed with the Nginx source. Installation instructions are below.''

mod_strip removes unnecessary whitespace (spaces, tabs, and newlines) from HTML documents. It can be used in combination with NginxHttpGzipModule to reduce page download times for both static and dynamic content. This software is alpha/beta quality but it works for me. mod_strip leaves intact comments as well as &lt;pre&gt; tags.

mod_strip is extremely fast. It parses HTML with a state machine and allocates no new memory buffers.

Example usage: location / { strip on; }

strip
syntax: strip on|off

default: off

context: main, http, server, location

Enables stripping of responses with MIME type of text/html.

Installation
To install, download the source tarball, expand it, and then compile nginx with the following option:

--add-module=/path/to/mod_strip-0.1

TODO

 * Generate state machine with Ragel
 * Write parsers for JavaScript/CSS
 * Ability to customize list of parsed MIME types

Newlines are not replaced by spaces
This:

Line number 1 Line number 2

Will be stripped down to this:

Line number1Line number 2

The correct behavior would be to strip to this:

Line number 1 Line number 2

This bug exists for technical reasons. Treating newlines as spaces will cause endtags preceded by newlines to be incorrectly formatted. That is, this:

 Hello 

Should still strip to this:

Hello

And not this:

 Hello 

Unfortunately, the way mod_strip is currently written, it is hard to treat both cases separately. Future versions of mod_strip may not remove newlines at all.

Reporting a bug
Please report bugs to Evan Miller.