Remove Whitespace from HTTP Response Payload

Problem this snippet solves:

Summary: Strip extraneous white space from HTML in the HTTP response payload Here is a simple iRule which uses a stream filter and STREAM::expression based iRule to two or more consecutive whitespace characters with a space. It hasn't been tested in production so try it on a test virtual server or test unit first!

Code :


       # Prevent server compression
       HTTP::header remove "Accept-Encoding"

       # Disable the stream filter by default

       # Check if server response is text based
       if { [HTTP::header Content-Type] contains "text" }{

              # Set the stream expression to match two or more consecutive whitespace characters
              # Replace them with a single space
              STREAM::expression @\s+@ @}
Published Jan 30, 2015
Version 1.0

Was this article helpful?