FAQ

Page Discussion Edit History

HttpStripModule

Contents

[edit] 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;
}

[edit] Directives

[edit] strip

syntax: strip on|off

default: off

context: main, http, server, location

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

[edit] 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

[edit] TODO

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

[edit] Bugs

[edit] 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.

[edit] Reporting a bug

Please report bugs to Evan Miller.