Most of you have heard by now that ColdFusion MX templates are compiled into Java. Some may wonder what the big deal is.
Many more of you may be surprised to learn that you can precompile CFMX templates. Do you know why you might want to? And if you've known previously about how to precompile CFMX templates, did you find that trying to do so with code outside the default\coldfusionmx\wwwroot directory (or \inetpub\wwwroot for IIS users) was troublesome?
I've got the solution to that problem as well. First, some background to bring everyone up to speed on the subject of compilation and precompilation in CFMX.
CFMX Templates Are Compiled
One of the great new benefits of ColdFusion MX is that, because it's built on an underlying Java platform, our ColdFusion templates are actually compiled into Java classes. They're not really executables, though, and they're not self-sufficient programs that can run on any Java (or even J2EE) platform, but the compilation takes place nonetheless.
Unlike in Java and many other languages, however, this compilation takes place automatically. Just as with previous releases of ColdFusion, you can create or edit your templates, and ColdFusion simply runs them as soon as they're changed. (Actually, JSP templates in the J2EE world work the same way.)
You needn't really concern yourself with the mechanisms of automatic compilation. It works without your doing anything. So why this article?
The Onetime Cost of Compilation to a User
Each of these features, the automatic compilation and the automatic detection of code changes, is a two-edged sword. There's the cost borne by the first user to execute a page after it's been created or edited. The request for that Web page will be delayed for a few seconds while CFMX compiles the code the first time. Some find this cause for concern.
The benefit of compiling, of course, is that once this "cost" has been paid by the first user to hit the page, each subsequent page hit is very fast; this is a onetime cost and recurs only if the file is later changed. That compiled code is saved and stored on disk (as a .class file that CF knows how to find and execute), and even if the server is restarted, that previously compiled file will be reused by the server to serve that template. There won't be any more waits for compilation until a developer changes the template again. (Well, almost. More about that in Part 2.)
But what if you deploy a large number of newly created or edited templates in your application? Or what if you frequently change them throughout the day? Then the number of automatic compilations grows. Consider the impact on the first users who hit such changed pages, or the first user hitting your multipage site after you've deployed a number of new templates. That first user may suffer delays on every page as he or she traverses through your site. Ouch.
Anyone who has gone through the ColdFusion Administrator for the first time after installing CFMX will understand the experience. At least that code doesn't change again after CFMX is installed. But you may hit a page some days later that no one else has hit yet, and you'll wait for that compilation then.






