Webpage acceleration series (III): webpage acceleration-webpage weight loss

Source: Internet
Author: User
(3) webpage acceleration-webpage weight loss

To complete the page to lose weight should first talk about the HTML language, it is an explanatory script language, more see (http://msdn.microsoft.com/library/default.asp? Url =/Workshop/author/DHTML. ASP, English), how can we "lose weight"? Because in HTML, there is no need for line breaks or spaces, however, various HTML files written in the editor can be viewed by the author easily.ProgramTherefore, a lot of spaces and line breaks are used. It seems that the fp2000 software will generate quite a lot of spaces to make the inner space of Your webpage very large. There are also some human-defined content that can be subtracted. For example, you need to apply multiple HTML attributes to one object, and these attributes are repeated, it will also make your page fat. Some different definitions that can produce the same results will also generate a lot of uselessCode. Next, let's take a look at the specific weight loss methods:

1. Software Compression Method
The easiest method is the software compression method. Some software dedicated to HTML slimming is used to lose weight on HTML pages. This method is easy and effective, however, for example, redundant HTML code caused by humans cannot be reduced, and redundant spaces and tabs can only be removed.

2. Design diet
This method is also very easy. Here we will only talk about a part of it, but more of it should be accumulated by ourselves. When designing a webpage, especially when designing a webpage with a software, you should use a good operation habit and correct method to optimize the page size you have compiled. For example, if you have text or images in a table that need to be centered, using cell center will produce less code than using text center; for example, when all the text on the page is a small word, the CSS method to define the text will produce much less code than a part of the plain text to be written.
Define the same color for a row in a table, so using the row definition (TR) will produce less code than using the cell definition color; for example, if most of the links on your page are to open a new window, you can set the default (base) of the page to open a new window, this will reduce the definition of opening a new window. The same is true for similar code.

3. Program diet
This is a high level of page weight loss. As you can see, there are a lot of code on the page that you want to share with others. If you can reduce these similar things, you can
How can we achieve this? Because the current web pages can all use a programming language JavaScript, which is completed by inserting HTML.
For some dynamic things, we can use it to lose weight. For example, the HTML link is as follows:
<TD align = middle width = 110> <a href = "http: // www.qianxun.com"> qianxun </a> </TD>
<TD align = middle width = 110> <a href = "http: // hdqs.126.com"> red beans </a> </TD>
<TD align = middle width = 110> <a href = "http: // stonetime.126.com"> stone time </a> </TD>
<TD align = middle width = 110> <a href = "http: // xiaokuen. on. NET. cn"> love garden </a> </TD>
<TD align = middle width = 110> <a href = "http: // lilicai. Yeah. Net"> taste </a> </TD>
<TD align = middle width = 110> <a href = "http: // broy.126.com"> FengHua </a> </TD>
There are a lot of content, but there are a lot of things that are the same, so we use programs to dynamically generate these things as follows:
Function LK (URL, txt ){
Document. Write ("<TD align = middle width = 110> <a href =" + URL + ">" + TXT + "</a> </TD> ")
Lk ("rongww. Yeah. Net", "<font color = Red> ronger's home ")
Lk ("hdqs.126.com", "")
Lk ("stonetime.126.com", "Stone time ")
Lk ("xiaokuen. on. NET. cn", "love garden ")
Lk ("lilicai. Yeah. Net", "taste ")
Lk ("broy.126.com", "FengHua ")
In this way, the content will be reduced, but if there seems to be a lot of links above, this code can be a lot of weight loss for you and increase the maintainability of the page, this program is just an example. Maybe it doesn't suit your needs, but this is what I tell you. You can design the program you need, make the page faster and better (for example, the year, month, and day drop-down boxes on my page are DW ("<option value =" + I + ">" + I + "</option> "), greatly reduces page network traffic ). Another method of Program-based weight loss is integrated. JS program ,. improper use of JS may slow down the page speed, but if you use it properly, you can use it locally. JS has another work efficiency. You can save the same code on different web pages with A. js file
The page capacity is reduced, and the page can be modified later.

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.