Print Page | Close Window

One script block or not?

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=4512
Printed Date: 30 March 2026 at 10:10am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: One script block or not?
Posted By: ngaisteve1
Subject: One script block or not?
Date Posted: 25 July 2003 at 12:45am
Just want to ask about writing code. I know that each time there is a <%%>, there will be a server trip. In order to minimize server trip, we should have one asp script block, which is the whole page just one <%%>. However, by doing this, can make the whole page every difficult to read, the indention etc. If not using this way, then will affect the performance cause by many server trip. So, what should be the best practice? I check out some big system, for webwiz is not using one script block and snitz is using one script block.



Replies:
Posted By: stephen
Date Posted: 25 July 2003 at 2:27am

From what other well experienced developers have said, including on this forum, it makes very little difference. This is an interesting post for me as I would be testing performance with these two methods as part of my final project.



-------------
"Doing easily what others find difficult is talent; Doing what is impossilbe for talent is genius." -- Henri Frederic Amiel ( 1828-1881)
http://www.121People.com - www.121People.com


Posted By: ljamal
Date Posted: 25 July 2003 at 8:17am
On a powerful web server you will not see much performance difference, but from a development outloook indenting code makes it infinitely easier to read.

I had a friend a couple years back that went to the trouble of creating a program that would remove all empty space from his code and FTP that code to his web server. There was about a 5-10% decrease in file, but very little difference in execution speed.

My preference is to use blocks of ASP and do as much code in one space as possible and then reference variables and arrays as needed. This means that all my SQL statements are executed and processed at one time and stored in arrays for use later. My typical page has a dense section of ASP at the top and bottom and small bit dispersed through the center with HTML elements.

Another note:
There is no additional server trip made for the execution of any single ASP page. Only one trip is made to the server which then processes and parses the request. What you are talking about is additional processing/ execution time which is why a 200 line page with no ASP loads faster than a page with 200 lines of ASP.



-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: dpyers
Date Posted: 26 July 2003 at 11:54am

"How do I make my ASP pages more efficient" - http://www.aspfaq.com/show.asp?id=2424 - http://www.aspfaq.com/show.asp?id=2424

"Does order matter when using different languages in ASP" - http://www.aspfaq.com/show.asp?id=2045 - http://www.aspfaq.com/show.asp?id=2045

 

The way it was explained to me many moons ago was that when you call a page with the .asp extension, an instance of asp.dll is invoked with associated server overhead to establish the instance. When the %> is found, the instance is shutdown - again with associated overhead. Intertwining asp and html either instantiates asp.dll for the page, or shuts it down whenever you change between asp and html. This little snippet from MS appears to support that ...

"Keep blocks of ASP server-side script together, rather than switching back and forth between server-side and client-side code. This switching usually happens when concatenating HTML with simple values from ASP, as when you are writing out an HTML table:

<%    For iCtr = 1 to 10  %>
<TR><TD>Counting ... <%= iCtr %></TD></TR>
<%    Next  %>


You can improve the code's by making it a single script block:


<%    For iCtr = 1 to 10
Response.Write "<tr><td>Counting " & iCtr & "</td></tr>"
      Next
%>


This technique has shown measurable and significant performance improvements."

BTW... The problem is even more pronounced with javascript... the interpreter instantiates after each CF/LF. If you note the javascripts available on the code sites. Those complicated ones done by very experienced javascript developers have had the cr/lf's removed. The scripts are all on a single line.

Wnen all is said and done however, being able to work with our code is also very important. I'd only worry about it if you have performance problems with the page, or if you have high utilization.

 



-------------

Lead me not into temptation... I know the short cut, follow me.


Posted By: WebWiz-Bruce
Date Posted: 26 July 2003 at 12:17pm

I did a test once, I had a page that was around 1000 lines long with 100's ASP blocks all over the place in the HTML.

I converted the whole thing to use only one ASP block and ran both the original and new versions seeing how long they took to process all the way down to 0.0000000 of a micro second. When I ran the tests there was no difference in process time at all.

Of course this maybe slightly different if the server was under heavy load.



-------------
https://www.webwiz.net/web-wiz-forums/forum-hosting.htm" rel="nofollow - Web Wiz Forums Hosting
https://www.webwiz.net/web-hosting/windows-web-hosting.htm" rel="nofollow - ASP.NET Web Hosting


Posted By: the boss
Date Posted: 26 July 2003 at 2:34pm
ASp came out when the most powerful server ws a dual processor pentium II 500 MHz..in todays age when we have much more powerful computers and processors like AMD and Intel Xeon...u will not see any visible performance  degradation unless u write such a worst code which uses up all the processor power...

-------------
http://www.web2messenger.com/theboss">


Posted By: Bunce
Date Posted: 26 July 2003 at 7:36pm

The differences were more prominent in ASP2.0 

I believe that MS article was written at that time.

Cheers,
Andrew



-------------
There have been many, many posts made throughout the world...
This was one of them.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net