Using ColdFusion's onRequestStart Method Adds Whitespace to Templates

After banging my head against my desk (which is glass by the way!) I finally figured out how to resolve an issue that may affect others out there using the ColdFusion onRequestStart method in their Application.cfc.

What Happened?
I was attempting to build a dynamic page that returned only text so that I could consume it in Flash using some ActionScript magic. After getting some errors from Flash, I decided to check the ColdFusion template I was trying to access. On the surface, everything looked fine. However, once I did a "View Source", I noticed that the ColdFusion page had some extra whitespace and carriage returns in it. This is not good, because ActionScript wants to read the entire document, whitespace and all!

So off I went, trying <cfsetting enablecfoutputonly="true">. That didn't do a thing! So I threw another CF bomb at it by wrapping everything in <cfprocessingdirective suppresswhitespace="true"></cfprocessingdirective>. Nothing. I know, you're thinking <cfsilent> aren't you? It was already there my friends, and nada. I'm telling you I removed every extra space in that template's code and didn't get any closer to getting rid of the extra space.

And that's when it hit me ... check the Application.cfc and see if there's anything in there that might be generating it. So off I went again, going through each line of code in my Application.cfc. I decided to start commenting out some of the methods to see what, if any, impact it might have on the template. When I worked my way down to onRequestStart() and commented it out ... everything worked as it should! Well, that's great! BUT ... I still wanted to use my onRequestStart() code.

So to start with, let's take a look at some generic onRequestStart code:


    <cffunction name="onRequestStart">
    
        <cfargument name="request" required="true" />
    
        <!--- re-start application from URL with ?init --->
        <cfif isDefined("url.init")>
            <cfset onApplicationStart() />
        </cfif>

    </cffunction>

In order to still use the onRequestStart method, it turns out all I have to do is remove any and all white space and carriage returns in the onRequestStart method. So the revised code would look something like this:

<cffunction name="onRequestStart" access="public" output="true" hint="Fires when prior to page processing."><cfargument name="request" required="true" /><!--- re-start application from URL with ?init ---><cfif isDefined("url.init")><cfset onApplicationStart() /></cfif></cffunction>

Hopefully this saves someone else from a sore forehead.

Comments
There are 2 other options. 1. set output="false" for the onRequestStart method, or 2. put your code within a <cfsilent> block.
# Posted By Brian Love | 3/31/09 11:58 AM
True, the output="false" would work as well. However, the <cfsilent> trick did nothing for me.

Another trick sent to me via twitter from Bradley Moore was to place <cfcontent reset="true" /><cfreturn true /> at the end. However, the trick is that they have to be on the same line without any whitespace between them.
# Posted By Stephen Withington | 3/31/09 12:08 PM
<cffunction name="onRequestStart" output="false">

all your functions should be set to output="false" unless you really need to output something without using RETURN.

# Posted By Jorrit | 4/1/09 3:12 AM
@Jorrit,
I agree and am glad you brought that up. Thanks!

# Posted By Stephen Withington | 4/1/09 7:27 AM
This summon accentuation can be totally distorted or to an awesome degree trapped. As you wind up being more OK with database programming, you will understand how to improve your SELECT enunciations, at last influencing your database to do however much work as could be ordinary and not crippling your programming vernacular of choice.
# Posted By Black Leather Jackets | 1/30/18 11:45 PM
This series of replica rolex watches http://www.swisswatchjust.co.uk is not only a re-engraved classic watch, but omega replica the traditional aesthetic features replica watchesand contemporary
http://www.ukreplicawatch.co.uk watchmaking process integration
# Posted By sdgyer | 3/25/18 10:36 PM
Things are very open and intensely clear explanation of issues. It was truly information. Your website is very beneficial. Click link to visit my site that will help you having a virtual world as the same as your real world you living. https://www.sims4-cheats.com/
# Posted By sims 4 cheats | 6/10/19 3:39 AM
This onRequestStart method is amazing and I am going to talk more about this method soon. As you know I have to write my essay and I am sure that if I include some info about this method, then my essay will be amazing.
# Posted By write my essay | 10/12/19 6:19 PM
Nice sharing amazing one keep sharing more thanks for all lovely one
# Posted By screw type air compressor | 2/18/20 12:43 PM
This Is Really Great Work. Thank You For Sharing Such A Good And Useful Information Here In The Blog

# Posted By rotary air compressor | 5/14/20 6:45 AM
Great article you have share with us lots of information to this topic with us, I really enjoy to reading this. keep it up.
# Posted By best VPS hosting service | 5/27/20 9:46 AM
This Is Really Great Work. Thank You For Sharing Such A Good And Useful Information Here In The Blog

# Posted By easternstylo | 6/2/20 11:12 AM
I am glad to see this brilliant post. all the details are awesome ad good in this post.
# Posted By hostgator vs hostinger | 6/5/20 1:29 AM
<a href='https://www.prohomeworkhelp.com/economics-homework...'>Economics Homework Help</a> the reliable help websites, we can say that assignment help is a reliable one. Their assignment writers across the globe are well trained in their chosen field of study which reflects in multiple offer. It is important to choose the best one among the many. Before choosing the one go for that website reviews first and then check the website like their services.
# Posted By Economic Homework help | 6/21/20 11:07 PM
Its a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work.
# Posted By Delhi Escorts | 8/13/20 5:51 AM
I love to read this post here is good information for us thanks for sharing with us.
# Posted By Mumbai Escorts | 11/5/20 12:39 AM
Knovva Academy offers both online and offline affordable learning facilities to its learners.
# Posted By Knovva Academy | 11/23/20 3:48 PM
This is a great inspiring article. I am pretty much pleased with your good work. You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post.
# Posted By Delhi Escorts Service | 2/21/21 1:03 AM
If you are looking for a call girl with whom you will complete all your sexual urges and make your days more romantic then visit our website and book a busty call girl for you.
http://www.sonalisharma.co.in/
https://www.delhi-escorts.in/
http://www.mallikakhan.in/
http://www.delhiescorts69.org.in/
# Posted By anika malhotra | 3/9/21 3:21 AM
This is a central post. I like this topic. This site has get-togethers of advantage. I discovered express bewildering things from this site. It causes me in various ways. Thanks for posting this over before long.
http://www.lucknowescorts.co.in/
http://www.thegurgaoncallgirls.com/
http://www.escortservicesindelhi.in/
http://www.independentescortgurgaon.in/
# Posted By parul sharma | 3/10/21 4:57 AM
I like your website very much, what a unique idea. Thanks for sharing. view list of:
# Posted By Delhi Escort | 3/13/21 8:01 AM
I am definitely enjoying your website. You definitely have some great insight and great stories.
# Posted By hi-teche.com | 3/15/21 1:20 PM
Finding the best female escorts in Hyderabad? Book call girls in Delhi 24*7 available. Click the link and get shot, call girl.
# Posted By Delhi Escorts Service | 4/9/21 9:37 AM
Great blog. To an outstanding degree like this, I have found stores of dazzling stuff on your blog. a commitment of appreciation is all together to offer this to us, keep it up!
<a href="https://www.escortservicefrankfurt.de/">; Escorts Service in Frankfurt </a>
<a href="https://www.frankfurtmodelescorts.de/">; Escorts Service Frankfurt </a>
<a href="https://www.frankfurtescortgirl.de/">; Frankfurt Escorts </a>
<a href="https://www.hifiescort.de/">; Frankfurt Escorts Girls </a>
# Posted By iemilyarden | 6/11/21 8:34 AM
The post is written in a standard way and it contains clear striking information for me. Thankful to your particularly focal information controller, and reason me ensuring to share articles here may help.
https://www.escortservicefrankfurt.de/
https://www.frankfurtmodelescorts.de/
https://www.frankfurtescortgirl.de/
https://www.hifiescort.de/
# Posted By iemilyarden | 6/11/21 8:36 AM
This is one conveniently key character brushing site page that has conveyed an impression of being astonishing resources which insurances instructive activities and materials to the goliath class of point subject.
https://www.amsterdamescortsservice.nl/
https://www.amsterdamescortnight.nl/
https://www.amsterdamsexservice.com/
https://www.amsterdamsexservice.nl/
# Posted By Isabella | 6/11/21 1:26 PM
This is a dispersing pushing article. I am on a focal appraisal substance with your astonishing work. You put to a stunning degree, especially strong information. Keep it up. Keep on writing for a blog. Which would need to several rationalities concerning World's best road course like.
https://www.bursaescortservice.com/
https://www.milanescortservice.com/
https://www.milanescortia.com/
http://www.escortserviceitalia.com/
# Posted By Amelia | 6/11/21 1:27 PM
This is a confusing degree focal post and the course by which you express your beginning and end post nuances that is moronically scrambling. A commitment of appreciation is with the goal for offering us this dazzling post.
https://www.femaleescortstoronto.com/
https://www.newyorkescortservice.org/
https://www.hongkongescortservices.com/
https://www.escortlounge.net/
https://www.escortgirlsingapore.com/
# Posted By Emma | 6/11/21 1:28 PM
An exceptionally well-made article, if from the general point of view all bloggers offered a common substance like yours, the web would be a surprisingly better place. You should keep it up.
http://www.peehu4u.com/location/nasirabad-escorts....
http://www.peehu4u.com/location/udaipur-escorts.ht...
http://www.peehu4u.com/location/salasar-escorts.ht...
http://www.peehu4u.com/location/rewari-escorts.htm...
http://www.peehu4u.com/location/pushkar-escorts.ht...
# Posted By Karishma Agarwal | 8/21/21 10:30 AM

© 2021, Stephen J. Withington, Jr.  |  BlogCFC was created by Raymond Camden – Version 5.9.004

Creative Commons License  |  This work is licensed under a Creative Commons Attribution 3.0 Unported License.  |  Hosted by Hostek.com