开发者

Is there any performance implication in using one big <cfoutput> tag?

开发者 https://www.devze.com 2023-01-07 21:28 出处:网络
I\'m being forced/payed to work on a Legacy ColdFusion project (I\'m an usual C# programmer) and one peculiarity with CF is that they have they\'re own tags that are supposed to blend with HTML (ba开发

I'm being forced/payed to work on a Legacy ColdFusion project (I'm an usual C# programmer) and one peculiarity with CF is that they have they're own tags that are supposed to blend with HTML (ba开发者_C百科d bad decision, IMO, since it just confuses the hell out of me even with the "starts with cf rule).

Besides this, they have the # character to indicate the start of CF "territory" much alike <% in ASP.Net or $ in Spark or so many equivalents. But this only gets parsed if inside a tag.

My question is: Is there a problem with opening one tag in the begining of the file and closing it, against using only when i'm going to use the # character?

To illustrate here's some code:

<cfoutput>
    Some text #SomeVar# Some text.<br />
    Some Images some other things #AnotherVar#
</cfoutput>

Against:

Some text <cfoutput>#SomeVar#</cfoutput> Some text.<br/>
Some Images some other things <cfoutput>#AnotherVar#</cfoutput>

Granted, this is might seem trivial for small content but i'm talking about a whole page.


Depending on the page contents, either is fine. There may be a performance impact (minor) by putting all of your page inside the CFOUTPUT tag, because the CFML engine needs to parse and scan the contents of the tag for executable code. Outside of the CFOUTPUT tag, the CFML engine can ignore the page as static content.

If you have CSS and HTML code that uses pound signs (for example named anchors or Hex color codes), you need to escape all pound signs (by adding a second one like "##") when within a CFOUTPUT. Because of this, I generally only put the CFOUTPUT around code I specifically want the CF engine to run.

That said, the CFML engine pays a bit of a performance penalty for constantly opening and closing the CFOUTPUT. If you're looping over come content, put the CFOUTPUT around the entire loop, rather than opening and closing it in each iteration of the loop.

Also, if you're having trouble knowing what code is CFML and what isn't, you might want to get a better IDE/editor for CFML like CFEclipse. It color codes the tags and lets you see the difference between CFML and HTML tags immediately. It's open source.


One problem you might find is that cfoutput is often used to display queries and they can not be nested inside of other cfoutput tags. So this will cause a 'Invalid tag nesting configuration' error

<cfoutput>
  <cfoutput query="qFriends">
    <li>#qFriends.fname# #qFriends.lname#</li>
  </cfoutput>
</cfoutput>


It should not be a big issue but be careful using hex-valued colors, you'll need to escape those with an extra #. If it was me, I would try to break down those huge chunks of content into smaller pieces. Let HTML, JS, Flash and CSS do their jobs and use CF for the server side.


If you want to put cfoutput at the beginning and end of the page, you have to use double sign ## for colors value.

0

精彩评论

暂无评论...
验证码 换一张
取 消