Coldfusion CFC and Variable Scopes

Posted: 04/03/2008

While recently working on a Coldfusion e-commerce website project, I became plagued with slow load time.  It seemed that it was taking unusually longer to load data from the database to website itself.  While the load time wasn't unbearable, it was enough to annoy me.

Was I just experiencing latency across the internet?  No, a speed test knocked that one out.  Perhaps it was my host provider.  Nope, not them either.

After looking at some of my other recent projects, I finally found the common denominator.  For the last few months I had been using CFCs in my Coldfusion website projects.  After comparing non-CFC websites to CFC based websites, I determined the issue was coming from the CFCs.

Off I went to research why this was occurring.  After doing some extensive Googling, I cam across this very interesting article on CFC Development by Rob Brooks-Bilson.  If you are new to CFCs, as I was, then I highly recommend reading this.  Alternatively, you can cruise on over to Raymond Camden's Coldfusion Blog for a wealth of information.

So, I discovered that the main culprit was the fact that I had not been scoping my variables.  Always eat your Wheaties and always scope your variables.  After going back and implementing this I found the load time had improved dramatically.  In fact, I was a little floored by how much of a difference it makes.

Sigh....now I need to go back and fix all my other website projects.  Lesson learned.

 
 
 
 

©2008 Keith Bates, Freelance Web Designer

Valid - XHTML | CSS