Page Discussion History

Difference between revisions of "HttpStripModule"

(Newlines are not replaced by spaces)
Line 71: Line 71:
<b> Hello </b>

Latest revision as of 23:11, 8 March 2013



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;



syntax: strip on|off

default: off

context: main, http, server, location

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


To install, download the source tarball ( File:Mod strip-0.1.tar.gz ), expand it, and then compile nginx with the following option:



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


Newlines are not replaced by spaces


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:


Should still strip to this:


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.