<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Monie Studios &#187; asp tips</title>
	<atom:link href="http://www.moniestudios.com/tag/asp-tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.moniestudios.com</link>
	<description>So much to learn, so little time!</description>
	<lastBuildDate>Sat, 21 Aug 2010 04:59:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>5 Tips To Speed Up Your ASP Page &#8211; P1</title>
		<link>http://www.moniestudios.com/tutorials/asp_speed_p1/</link>
		<comments>http://www.moniestudios.com/tutorials/asp_speed_p1/#comments</comments>
		<pubDate>Tue, 12 May 2009 07:07:52 +0000</pubDate>
		<dc:creator>Monie</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[asp speed]]></category>
		<category><![CDATA[asp tips]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[speed up]]></category>

		<guid isPermaLink="false">http://www.moniestudios.com/?p=325</guid>
		<description><![CDATA[This quick tips will teach you how you can get the best out of your ASP application. Part one will be discussing about some basic tips and part two will be covering in a lot more detail.]]></description>
			<content:encoded><![CDATA[<p>There are a few things that you can do to speed up an ASP script. In other words, decreasing the execution time of a script. The reason that those scripts take so long is not necessarily related to the database activity and ASP execution but to the rendering of html, (especially tables) by a browser.</p>
<p>All that said, these tricks will probably increase ASP performance even more if your site is really busy. So, are you ready? Here we go…</p>
<h2>Introduction</h2>
<blockquote><p>ASP pages are executed “on the fly” by a server when they are requested by a user. Because they are not <span style="text-decoration: underline;">*compiled</span> (script is much slower than a compiled object), complex ASP scripts can be about four times slower than plain HTML, and two to three times slower than <span style="text-decoration: underline;">*ISAPI</span>, when they are first requested. Afterward, the compiled version of the page is cached in server memory, making subsequent requests significantly faster.</p></blockquote>
<p>Make your users wait too long and they will abandon your site for a more efficient one. So, all the work, effort and most importantly the joy that you have put into that ASP project is somehow worthless! So what can you do about it?</p>
<p class="tips"><span style="text-decoration: underline;">*<strong>Compiled</strong></span>: When a user/client requests an ASP page (page that has the .asp extension) by sending an HTTP Request to the Web server ,the file will then be sent  to the appropriate <span style="text-decoration: underline;"><strong>*ISAPI</strong></span> extension which is the Asp.dll for compilation before display any dynamic content to the user. Note: This step does not occur when the client requests an HTML file that has the .htm extension.</p>
<h2>1. Disabling Session State</h2>
<p>By default, IIS prepares to maintain a user&#8217;s Session on every page. Of course not every page uses session variables, but IIS is prepared them by default. If you know a particular page that will not use session variables, you can explicitly tell IIS that it does not need to worry about maintaining session state.</p>
<p>When you disable session state, any session variables or methods will not be available. In other words, a simple call like <strong>&lt;% Session.Abandon %&gt;</strong> or setting up a variable like this:</p>
<pre class="brush: vb;">
&lt;% Session(&quot;username&quot;) = Request.Form(&quot;username&quot;) %&gt;
</pre>
<p>will result in an errors. To disable session state you must make &#8220;@&#8221; declaration at the top of your page like the following:</p>
<pre class="brush: vb;">
&lt;% @LANGUAGE=&quot;VBSCRIPT&quot; %&gt;
&lt;% @EnableSessionState = False %&gt;
</pre>
<p>Putting it all together, we will have something like this:</p>
<pre class="brush: vb;">
&lt;% @LANGUAGE=&quot;VBSCRIPT&quot; EnableSessionState = False %&gt;
</pre>
<p class="tips"><strong>Note</strong>: To do more than one &#8220;@&#8221; declaration, like declaring a script language, you would put all the directives on the same line, otherwise you will get an error message saying that &#8220;The @ command can only be used once within the Active Server Page.&#8221;</p>
<h2>2. Declaring Option Explicit</h2>
<p>One of the most important things I always do when creating my first ASP page is to declare <strong>Option Explicit</strong> on top of every page before assigning or declaring any variable in that page. Option Explicit increases the speed of a page by not forcing ASP to create a temporary instance of every variable when it is found during execution.</p>
<p>Option Explicit will throw an error if you have not declared every variable that you used in your ASP page by using the &#8220;Dim&#8221; statement. Not only does Option Explicit lead to more readable and maintainable code, Option Explicit also help you debug your code a lot easier.</p>
<p>The Option Explicit statement must be directly underneath the &#8220;@&#8221; declarations or you will get an error. With option explicit, here is our ASP page:</p>
<pre class="brush: vb;">
&lt;% @LANGUAGE=&quot;VBSCRIPT&quot; EnableSessionState = False %&gt;
&lt;% Option Explicit %&gt;
</pre>
<h2>3. Enabling The Response Buffer</h2>
<p>Another thing you can do is set the response buffer property to true. This buffering increased performance because IIS doesn&#8217;t need to bother sending any HTML information to the client until the entire ASP script has been processed. The html is then transferred all at once instead of in small pieces during runtime.</p>
<p>To enable buffering in our asp page, we add the &#8220;<strong>Response.Buffer = True</strong>&#8221; line below our previous code. So our new ASP page looks like this:</p>
<pre class="brush: vb;">
&lt;% @LANGUAGE=&quot;VBSCRIPT&quot; EnableSessionState = False %&gt;
&lt;% Option Explicit %&gt;
&lt;% Response.Buffer = True %&gt;
</pre>
<h2>4. Don&#8217;t Switch ASP Scripting Engines In The Same Page!</h2>
<p>Sometimes you have to switch scripting engines in an ASP page. What I mean is your current &#8220;@&#8221; language declaration is VBScript and then all of a sudden, you need to call a JavaScript object like the Browser object. So you build some &#8220;<strong>SCRIPT RUNAT=SERVER</strong>&#8221; tags set to another language and do what you have to do&#8230;</p>
<p>Well, when you do that, you really taxing ASP. You’re making it doing two separate compilations, combine the code and finally, execute the final code. It is adding two extra steps in your normal execution of an ASP scripts. If you find yourself doing the switch back and forth between JavaScript / VBScript or PerlScript, you might want to consider switching to the language used the most within the affected pages and just rewrite whatever code isn&#8217;t that language on the page.</p>
<p>Since ASP keeps pages independent of each other, it really doesn&#8217;t matter if Page1.asp is written in JavaScript, Page2.asp is written in Perlscript and Page3.asp is written in VBScript. If you can live with that type of implementation, your pages will be faster than those that use more than one scripting engine on the same page.</p>
<h2>5. Minimised Response.Writeblock Execution</h2>
<p>Never heard about it huh? You’re not alone! It&#8217;s a hidden property within the response object. What does it do? Well, whenever you break up your delimiters  “&lt;% %&gt;” tags to write html codes, you are making the compiler to call the &#8220;Response.WriteBlock&#8221;. Consider this code:</p>
<pre class="brush: vb;">
&lt;% @LANGUAGE=&quot;VBSCRIPT&quot; EnableSessionState = False %&gt;
&lt;% Option Explicit %&gt;
&lt;% Response.Buffer = True %&gt;

&lt;html&gt;
&lt;body&gt;

&lt;%
	Dim i
	For i = 0 to 10
%&gt;

&lt;% Response.Write i %&gt;
&lt;% Response.Write(&quot;&lt;br&gt;&quot;)%&gt;
&lt;% Next %&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>When the compiler gets a hold of this code, it has to render it by calling Response.WriteBlock over and over again (in this example it is called 7 times). Once for each time you broke up the asp script delimiters tag (&lt;% %&gt;). You can make this code faster by rewriting it in the following way. So far, our ASP page will look like this:</p>
<pre class="brush: vb;">
&lt;% @LANGUAGE=&quot;VBSCRIPT&quot; EnableSessionState = False %&gt;
&lt;%
	Option Explicit
	Response.Buffer = True

	Response.Write (&quot;&lt;html&gt;&quot;)
	Response.Write (&quot;&lt;body&gt;&quot;)

	Dim i
	For i = 0 to 10
	Response.Write i &amp; &quot;&lt;br&gt;&quot;
	Next

	Response.Write (&quot;&lt;/body&gt;&quot;)
	Response.Write (&quot;&lt;/html&gt;&quot;)
%&gt;
</pre>
<p>This code causes the compiler to only call Response.WriteBlock two time, saving cycles, memory and increasing the speed of the ASP code execution.</p>
<h2>P2 &#8211; Part 2</h2>
<p>On the next part of this article, I&#8217;ll be talking about more detail and complex tips for asp execution such as how to use proper asp recordset, some database connection tips and the Request Object function.</p>
<p>Stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.moniestudios.com/tutorials/asp_speed_p1/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
