Whitespace Suppression

Christian Cantrell posted a blog entry about expanding CFML whitespace suppression by leveraging CFMX's J2EE underpinnings. There seems to be a fair amount of happiness that this solution was made known (especially such a simple one). Two things I see here:

  1. people need to stop thinking about CFMX and a CF server and start thinking about it as the J2EE application it really is. You're getting a hell of a lot of power, basically for free, and the vast majority (or so it seems) totally ignore it.
  2. this looks like a good product feature for CFMX to have natively, maybe even in Blackstone, though it might be too late in the dev cycle for that.

What makes this more interesting to me is that I had a private discussion with Vince from New Atlanta about BlueDragon's whitespace suppression capabilities last week. CFMX's definition of whitespace suppression (both the CF admin option, and CFPROCESSINGDIRECTIVE's behaviour) is that all whitespace between CFML tokens (tags or hash-wrapped expressions) is consolidated into a single space. All other whitespace is left alone. BlueDragon's definition (same scope) is that after the whitespace-suppressed block is fully generated, all runs of whitespace are replaced with a space.

These sound pretty similar, until you realize that BD is drastically modifying your page's generated content, which has great consequences for inlined javascript (try using a // comment), PRE-formated text, and content for TEXTAREA tags.  Unfortunately, BD doesn't provide CFMX-compatible whitespace suppression in addition to this built-in overall whitespace suppression, so your in-code whitespace suppression mechanisms are pretty much incompatible with one or the other. BD's mechanism, however, is of nearly identical scope to the servlet filter solution Christian blogged about.

I'm happy to say that in the next version of BD (partly as a result of my discussion with Vince), the whitespace suppression mechanism will compress whitespace in a slightly more conservative manner, being more aware of newlines and such. This should remove the problems with inlined javascript, but will not solve the PRE and TEXTAREA issues. I also suggested that rather than trying to do it all with one option, they should split the function into CFMX-compatible suppression and then separately generated-content whitespace removal, so that you can just do the CFMX-compatible part. We'll see if that happens.

Also, just to throw this into the mix, using things like mod_deflate will generally give you an enomrous savings over simple whitespace suppression, especially if you're using CFML's built-in suppression facilities effectively already.

One response to “Whitespace Suppression”

  1. Alan

    Removing whitespace from pages is one way to go. Personnally i don't give it to much thought as i use CFSILENT in a lot of places to put in runs of CFML logic. But that aside, the best way to reduce your pages without any hassle from a CFML point of view, is to enable mod_gzip and you can see real leaps in page size reduction. You'll save a huge amount in bandwidth and the browser will render your page faster as it has all the information quicker than waiting for it to stream in from the server.

    GZIP can make a huge difference to XML output where lots of repeated tags are present; for example your RSS feeds will get a major boost.