Welcome!

ColdFusion Authors: Maureen O'Gara, Hovhannes Avoyan, Yakov Fain, Pat Romanski, Liz McMillan

Related Topics: ColdFusion

ColdFusion: Article

CFDJ Feature — Create a Pseudo-dynamicWeb Site with CF

What to do when the web server doesn't support ColdFusion

Another benefit of creating and deploying a pseudo-dynamic Web site is better performance. While the performance of a properly written dynamic ColdFusion application is very good, it's not going to surpass the performance of a static Web site. With this technique ColdFusion is used to create batches of files that are manually uploaded to a Web server and served statically. So the performance penalties normally associated with dynamic Web sites are avoided. In other words, you will always get better performance from a pseudo-dynamic (i.e., static) Web site than you will from a dynamic Web application even if ColdFusion powers that application.

The fourth and arguably greatest benefit of this technique stems from the use of Dreamweaver 8 templates. Being responsible for several static Web sites, I always use Dreamweaver 8's "templates" feature so that whenever I need to make a routine change to a static site, all I need do is change the Dreamweaver template and all of the pages in the site (that use that template) are changed automatically. Therefore, when using <CFFILE> to write static Web pages to the ColdFusion server, I make certain to retain all Dreamweaver template references in the HTML source code. Dreamweaver embeds template references in the HTML source code as HTML comments. Keeping these template references in the HTML source code ensures that my ColdFusion-generated static files will be "linked" to the Dreamweaver template. This means that when (not if) there is a need to revise the Dreamweaver template to accommodate some routine change in the HTML source code, all of the static pages that were generated with <CFFILE> will be changed automatically by Dreamweaver. This is a terrific ancillary benefit because it saves me (or someone else) from having to recreate all of the ColdFusion-generated static pages from scratch just to accommodate routine changes to the HTML source code.

As I mentioned earlier, the <CFDOCUMENT> tag can be used to write PDF and Flashpaper documents to a server. By modifying the <CFFILE> technique, it's possible to create any number of unique PDF or Flashpaper documents from database information in the same way that HTML files are created from database information using <CFFILE>. This time, however, we loop over the <CFDOCUMENT> tag (not <CFFILE>) and specify the filenames via the <CFDOCUMENT> tag's "filename" attribute as shown in Listing 5.

Note that this code omits the <CFSAVECONTENT> and <CFFILE> tags since they are no longer needed. Conceptually this code is the same as Listing 3 because we're still looping over a query and writing a single output file to the ColdFusion server on each pass through the loop. The "filename" attribute of the <CFDOCUMENT> tag is used to specify the full path and filename of the PDF files to be written to the server. As we did before with <CFFILE>, we dynamically construct sequential filenames for the PDF output files and specify "PDF" as the output format in the <CFDOCUMENT> tag. This results in filenames such as "p1.pdf," "p2.pdf," etc. The "overwrite" attribute of the <CFDOCUMENT> tag enables us to overwrite and replace any existing PDF files that may reside in the target directory on the server. The code in Listing 5 will create a unique PDF document for each record retrieved by the "listAllRecords" query; each PDF file will be populated with the data from a single database record and then written to disk.

You may receive the error message "The request has exceeded the allowable time limit" when executing an exceptionally long running template such as the code in Listing 5. To remedy this, you can use the "requesttimeout" attribute of the <CFSETTING> tag to increase the timeout limit for the template and override the ColdFusion Administrator's default timeout setting. Just insert the following code at the top of the template:

<CFSETTING REQUESTTIMEOUT = "360"
ENABLECFOUTPUTONLY = "no">

This will reset the timeout limit for the template to six minutes (i.e., 360 seconds) and preserve the ColdFusion Administrator's default timeout setting for all other templates on the server.

Conclusion
ColdFusion's <CFDOCUMENT> and <CFFILE> tags enable the rapid creation of static files, and each file can be populated with unique data from a database. This technique can be used to create any number of HTML, PDF, or Flashpaper documents for immediate deployment on a static (non-ColdFusion) Web site. If you have database information you need to display on a Web site but no ColdFusion support on the site, you could use this technique to create as many static files as there are records in your database. You could then upload those files and serve them statically from your site. Advanced ColdFusion developers could even implement an Event Gateway or employ the <CFSCHEDULE> tag to periodically generate a fresh set of static files whenever the database information changes or according to some preset schedule. Then it's just a matter of replacing the old files on the Web server with the new ones. Web servers that have ColdFusion support may also benefit because files (especially PDF and Flashpaper documents) could be periodically batch-generated and uploaded to the server rather than being served dynamically in real-time. This would lighten the ColdFusion server's processing load and most likely improve performance.

Needless to say, both the <CFFILE> and <CFDOCUMENT> tags are extremely powerful and important development tools. They come in very handy when you're a webmaster like me and responsible for one or more static Web sites that have no ColdFusion support. In such situations you need to get creative with ColdFusion or you could find yourself hand-coding hundreds (or thousands) of static Web pages. Obviously, this would be a mind-numbing, time-consuming exercise even if you use Dreamweaver's templating feature. Whenever you need to publish static text, HTML, PDF, or Flashpaper documents, the <CFFILE> and <CFDOCUMENT> tags should come to mind. Using them is simplicity itself, and the benefits can be enormous. As for me, I was able to accomplish another "impossible" task with ColdFusion MX 7 and save precious time for other development projects. So all of the harried, overworked ColdFusion developers out there should relax, take a deep breath, and repeat after me: "ColdFusion can do anything."

More Stories By Michael Markowski

Michael Markowski works for the Air Protection Division at the Environmental Protection Agency and is a Macromedia/Adobe Certified Professional.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.