Skip to main content
ModPageSpeed 2.0: AVIF, WebP, and critical CSS — up to 69% less page weight on the live demo

Collapse whitespace

HTML

Removes redundant whitespace from the HTML.

Filter collapse_whitespace · Filter docs

A mod_pagespeed 1.15 filter. ModPageSpeed 2.0 applies it as part of one always-on pipeline, not as a separate switch.

Both frames render identically — that's the goal. The win is in the bytes and requests below, not the look. They're served live by mod_pagespeed 1.15 on demo-httpd-1.1.modpagespeed.com; the optimized frame applies only this filter. Right after a cache purge it may briefly match the original while the worker rewrites it — reload to see the result.

Measured impact

HTML size

274 B 232 B
−15%

What changed in the source

The page's HTML, before and after this filter. Red lines are removed, green lines are added.


                
                  
<html>
-
- <head>
- <title>collapse_whitespace example </title>
- <script> var x = 'Hello, world!';</script>
- </head>
-
- <body>
- Whitespace is collapsed
-
- in general.
- <pre>
+ <head>
+ <title>collapse_whitespace example </title>
+ <script> var x = 'Hello, world!';</script>
+ </head>
+ <body>
+ Whitespace is collapsed
+ in general.
+ <pre>
But not in a
&lt;pre&gt; tag.
</pre>
- </body>
-
+ </body>
</html>

Run this on your own site

This is one of 47 filters mod_pagespeed 1.15 applies in place — self-hosted on Apache, nginx, and IIS. Install and run it: it optimizes right away and adds an X-PageSpeed-Warn: unlicensed header until you license it. A commercial license is required for production use.