| By Michael Markowski | Article Rating: |
|
| March 14, 2007 04:00 PM EDT | Reads: |
11,029 |
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."
Published March 14, 2007 Reads 11,029
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
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.
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Adobe LiveCycle Enterprise Suite 2 for Cloud Computing
- Adobe Betas Target RIAs and Cloud Computing
- Adobe Cans Another 9% of its Workforce
- Moyea DVD4Web Converter V2.0 Converts DVD to FLV Fast and Synchronously with Watermarks
- Adobe Fiddles with its Web Apps
- Adobe & Salesforce Cut Cloud Deal
- Hosting.com Launches ColdFusion 9 in the Cloud
- The Real Time Infrastructure Ultimatum
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Eval JavaScript in a Global Context
- Fig Leaf Software to Exhibit at Government IT Conference & Expo
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Is Microsoft as Free as Open Source?
- Adobe Reader Sued
- The Planet Named “Bronze Sponsor” of Cloud Computing Expo
- Microsoft Expression Web Has Got Game
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Bruce Chizen Joins Voyager Capital as Venture Partner
- My Top Seven Wishes From Adobe MAX 2009
- The Next Programming Models, RIAs and Composite Applications
- Where Are RIA Technologies Headed in 2008?
- Constructing an Application with Flash Forms from the Ground Up
- AJAX World RIA Conference & Expo Kicks Off in New York City
- CFEclipse: The Developer's IDE, Eclipse For ColdFusion
- Personal Branding Checklist
- Adobe Flex 2: Advanced DataGrid
- Has the Technology Bounceback Begun?
- Building a Zip Code Proximity Search with ColdFusion
- i-Technology Viewpoint: We Need Not More Frameworks, But Better Programmers
- The Asynchronous CFML Gateway
- Web Services Using ColdFusion and Apache CXF
























