Eliminate ColdFusion Whitespace Once and For All

Since I’m at Macworld this week, and consequently don’t have a lot of time to
put into my weblog, I’m going to be lazy, and reprint a comment that was sent to
me by Jon Alsbury. It was submitted in response to a post entitled Controlling
Whitespace in ColdFusion
. John writes:

The most effective (and easy to implement) technique for reducing whitespace in
CFMX generated pages I have discovered so far is to set up a simple servlet filter
to intercept the response in order to strip out whitespace before it is returned
to the client. The filer I’ve been using for this is called Trim Filter and can
be downloaded here:

http://www.servletsuite.com/servlets/trimflt.htm

Setup is easy: simply download trimflt.jar from the above URL, drop it into your
‘cfusionmx/lib’ directory. Add the following to ‘cfusionmx/wwwroot/WEB-INF/web.xml’:

<filter>
<filter-name>trimFilter</filter-name>
<filter-class>com.cj.trim.trimFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>trimFilter</filter-name>
<url-pattern>*.cfm</url-pattern>
</filter-mapping>