Blog Post RSS ?

Blogs » ColdFusion » Suppressing White Space
 

Suppressing White Space

by davidjmedlock

…posted by davidjmedlock:

Over the weekend I happened to be working on a project with another developer and he emailed me about an issue with a custom tag that he was using. He said that there was an inordinate amount of white space in his documents. In fact, the document with all the white space in it was about 40KB as opposed to the document without white space being around 16KB. Yikes!

The reason for this is because in the execution of the page, the server must translate the CFML into p-code, which is executable by the application server. In the conversion, the CFML becomes whitespace.

When you have ColdFusion code in a display document and then view the source, you’ll see that everywhere the ColdFusion code was is now white space. This can cause your documents to be bloated and it can eat up your bandwidth quickly.

The best way that I’ve discovered for suppressing whitespace is to go into ColdFusion Administrator, go to the Settings page and click “Enable Whitespace Suppression”. This will drastically reduce the size of your pages, especially if you are doing anything database intensive where you have large queries. It will also make your code more readable.

I know that there are ways to do this in code, using cfprocessingdirective, cfsetting, and cfsilent, but with the ability to set it up in the server itself, I really don’t see any reason to have to do it in code. Even if you’re on a shared host, you should email them and ask them to make this small change for you. It will decrease the bandwidth used and they should be able to do it for you without a problem. (If they ask you what the ColdFusion Administrator is, then find another host!)

There’s more information about displaying output in the Programming ColdFusion book by OReilly. Chapter 11 is where you’ll want to look.

As a side note, I looked around a little bit to find out if enabling the suppression of whitespace has any noticeable effect on server performance and I haven’t seen anything in there about it. I could see how it might slow it down ever so slightly, since it now has to clean up after itself, but it also seems that it may speed up just a very little bit since it is dealing with less data in terms of memory… If anyone has references on the matter, I’d be interested to see them.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Ping.fm
  • Twitthis

Related posts:

  1. Focus On Typography, Part 4: Space Let your text breathe by putting some space around it,...
  2. Can You Get Manipulative? Take This ColdFusion Quiz and Find Out! We've just published a new quiz and tutorial on manipulating...
  3. Fast Publishing of RDFa with Dreamweaver Martin McEvoy has just released the RDFa Documents extension which...
  4. Server-side JavaScript Will Be as Common as PHP Despite the fact that JavaScript has been typecast as the...
  5. Build Your Own URL Shortener Kay's latest tutorial walks you through the creation of a...

This post has 13 responses so far

Sponsored Links

SitePoint Marketplace

Buy and sell Websites, templates, domain names, hosting, graphics and more.

Follow SitePoint on...