What is the most effective way to write ASP-generated content to the response stream?

Source: Internet
Author: User
When you first started to learn ASP, the HTML included in the book contains ASP
Later, output HTML with Response.Write
But now read this article, do you really want to write a sentence of Response.Write ("& _?
You tell me?
-------
(Turn http://www.ccidnet.com/html//tech/web/2000/11/10/58_1298.html)
What is the best choice for improving ASP performance (i)
(Author: Green Apple studio compiled November 10, 2000 17:20)

What is the most effective way to write ASP-generated content to the response stream?
One of the most important reasons for using ASP is to generate dynamic content on the server. So obviously, the starting point of our testing is to determine the most appropriate way to send dynamic content to the response stream. Of the many choices, two are most basic: one is using inline ASP tags and the other is using Response.Write statements.

To test these choices, we created a simple ASP page that defines the variables and then inserts their values into the table. Although this page is very simple and not very practical, it allows us to isolate and test some separate issues.

Using ASP inline markup

The first test includes the use of inline ASP tags <%= x, where x is an assigned variable. So far, this method is easiest to perform, and it keeps the HTML part of the page in a format that is easy to read and maintain.

<% OPTION EXPLICIT

Dim FirstName

Dim LastName

Dim middleinitial

Dim Address

Dim City

Dim State

Dim PhoneNumber

Dim Faxnumber

Dim EMail

Dim Birthdate

FirstName = "John"

MiddleInitial = "Q"

LastName = "Public"

Address = "Main Street"

City = "New York"

State = "NY"

PhoneNumber = "1-212-555-1234"

Faxnumber = "1-212-555-1234"

EMail = "John@public.com"

Birthdate = "1/1/1950"

% >

< HTML >

< head >

< title >response test</title >


< BODY >

< H1 >response test


< TABLE >

< TR >< TD >< B >first name:</></td >< TD ><%= FirstName% ></td &GT;&L T /tr >

< TR >< TD >< B >middle initial:</></td >< TD ><%= middleinitial% ></t D ></tr >

< TR >< TD >< B >last name:</></td >< TD ><%= LastName% ></td >< /tr >

< TR >< TD >< B >Address:</b ></td >< TD ><%= address% ></td ></t R >

< TR >< TD >< B >City:</b ></td >< TD ><%= City% ></td ></tr >

< TR >< TD >< B >State:</b ></td >< TD ><%= State% ></td ></tr &G T

< TR >< TD >< B >phone number:</></td >< TD ><%= phonenumber% ></td &G t;</tr >

< TR >< TD >< B >fax number:</></td >< TD ><%= faxnumber% ></td &GT;&L T /tr >

< TR >< TD >< B >EMail:</b ></td >< TD ><%= EMail% ></td ></tr &G T

< TR >< TD >< B >birth date:</></td >< TD ><%= birthdate% ></td &GT;&L T /tr >

</table >

</body >


Complete code for/app1/response1.asp

Previous best (reaction speed) = 8.28 msec/page

Use the Response.Write statement on every line in the HTML

Many of the better learning documents suggest avoiding using the previous approach. The main reason for this is that in the process of applying reaction time to the output page and the processing page, a problem called context conversion occurs if the Web server has to convert between sending pure HTML and processing scripts. When most programmers hear this, their first reaction is to wrap each line of the original HTML in the Response.Write function.

...

Response.Write ("< HTML >")

Response.Write ("< head >")

Response.Write ("< title >response test</title >")

Response.Write ("
Response.Write ("< body >")

Response.Write ("< H1 >response test


Response.Write ("< table >")

Response.Write ("< tr >< TD >< B >first name:</></td >< td >" & FirstName & "</td ></tr >")

Response.Write ("< tr >< TD >< B >middle initial:</></td >< td >" & Middleiniti Al & "</td ></tr >")

...

Fragments of/app1/response2.asp

Previous best (reaction speed) = 8.28 msec/page

Reaction time = 8.08 Msec/page

difference = -0.20 msec (Decrease 2.4%)

We can see that this is a very small gain in performance compared to using inline tags, perhaps because the page loads a large bunch of small function calls to the server. The biggest disadvantage of this approach is that since HTML is now embedded in the script, the scripting code becomes more verbose and harder to read



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.