From html output format to html Performance Optimization

Source: Internet
Author: User
When I was working on a project today, I used <Asp: Repeater ID = "getnews" runat = "server">
<HeaderTemplate> <ul> </HeaderTemplate>
<ItemTemplate> <li> <% # string. format (LTP. common. stringPlus. unRepalceStr (ConfigurationManager. appSettings ["newDisplay"]. toString (), Eval ("NewId"), Eval ("Title"), Eval ("DataTime") %> </li> </ItemTemplate>
<FooterTemplate> </ul> </FooterTemplate>
</Asp: Repeater>

When I view the source code, this <ul> <li> ..... </li> <li> .... </li> .. </ul>
I thought it would be too good. If other programmers see the source code for readability, it would be too bad for uniformity.
Then I tried to add <% = "\ n" %> in front of the <li> label.
Hey, you can generate neat html.
<Ul>
<Li>... </li>
...
</Ul>
However, at this time, my mind flashed a sentence that I often saw when reading a blog. I wanted to put the customer experience first. Then I thought of performance problems and found that the size of html files generated based on the first type of performance was very small,
Then I found an html file with the same performance and compared it with the following two formats: the first is generated by aspx, and the second is after the carriage return jump is removed from the formatted string.  
 
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> No title page </title>
</Head>
<Body>
<Form name = "form" method = "post" action = "Default. aspx" id = "form">
<Div>
<Input type = "hidden" name = "_ VIEWSTATE" id = "_ VIEWSTATE" value = "/wEPDwUKLTM5Nzg1MTUzNGRk8/uw5bMqRP4/v052GLT5Pylxl1U ="/>
</Div>
 
<Div>
 
<Input type = "hidden" name = "_ EVENTVALIDATION" id = "_ EVENTVALIDATION" value = "/wEWAgKvrovKBALs0bLrBpKJ1v/9L5AmtBkr3s3q + NybkCgd"/>
</Div>
<Div>

<Ul>
<Li> <a href = "shownewinfo. aspx? & Newid = 1 "title =" experiment-Welcome to "> experiment-Welcome to </a> <span class =" datetime "> 2009/7/26 0:00:00 <span> </li>
</Ul>
 
<Textarea name = "TextBox1" rows = "2" cols = "20" id = "TextBox1" style = "height: 123px; width: 289px;">
& Amp; lt; li & amp; gt; & amp; lt; a & amp; nbsp; href = & amp; quot; shownewinfo. aspx? & Amp; newid = {0} & amp; quot; & amp; nbsp; title = & amp; quot; {1} & amp; quot; & amp; gt; {1} & amp; lt;/a & amp; gt; & amp; lt; span & amp; nbsp; class = & amp; quot; datetime & amp; quot; & amp; gt; {2} & amp; lt; span & amp; gt; & amp; lt;/li & amp; gt; </textarea>

</Div>
</Form>
</Body>
</Html>

Code
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

I don't need to talk about the second one. The first file in lower case is 1.18kb and the second one is 1.06kb. You may laugh at me and I know it, but I 'd like to talk about it. If we are doing a program, finally, use string processing or regular expressions to remove the carriage return, which can greatly reduce the file size. Example: baidu homepage. And then use the compression transfer method. To improve performance:

Disadvantage: the html generated by the client is messy. It seems that the dom tree structure is lost. However, I think this will better protect the code. It is uncomfortable for others to view your source files. In this way, it can be protected. (I 'd like to talk about cainiao's opinions before sending them to the home page. Please include them !)

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.