FAQ

Page Discussion History

HttpStripModule

Revision as of 23:11, 8 March 2013 by Emiller (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Contents

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 <pre> tags.

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

Example usage:

location / {
    strip on;
}

Directives

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 ( File:Mod strip-0.1.tar.gz ), 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

Bugs

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:

<b>
Hello
</b>

Should still strip to this:

<b>Hello</b>

And not this:

<b> Hello </b>

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.