We know that in HTML, you not only have to make good-looking web pages, but also consider the optimization of web pages. So today I will give you ideas on how to optimize HTML web pages. I have summarized 5 points. Let’s take a look
Change table to div layout
Try to reconstruct the table tag layout html into the div layout, which can save at least 40% of the code. Since the div code is less than the html webpage with table layout, the search engine index weight is also better than the html webpage with table layout. Reduce and streamline div, span, ul li and other series of tags
When laying out DIV+CSS web pages, we can sometimes save some DIV layout code and reduce the amount of code.
The following case code:
<div class="div"> <ul> <li>DIV</li> <li>DIV</li> <li>DIV</li> </ul> </div>
can be changed to:
lass="div"> <li>DIV</li> <li>DIV</li> <li>DIV</li> </ul>
This can save a pair of div tags, thereby reducing the amount of html code , which plays the role of compressing html. In this way, directly naming the css style class for ul can distinguish the use of ul li list tags in different places on a page.
DeleteExcess spaces Delete excess spaces and line breaks, which can effectively compress the bytes occupied by the html code. Generally, after the development is completed, the code in the html can be deleted, line breaks, and line breaks. Space content.
You can use DW software to batch delete spaces between tags in html
For example:
<div class="div"> <div ...></div> </div>
You can delete spaces and line breaks:
< div class="div">
This can save bytes occupied by spaces and line breaks.
Note that the published version of the web page can use DW to delete redundant spaces and blank lines. If you want to edit again, go to DW software to format the code.
TableIn type layout, use table instead of div layout appropriatelyIf it is a table data list layout, we'd better choose table, because using table for table layout is better than div layout, using table layout saves
html tagcode and saves css style than div layout. As shown in the table below
Data type, it is recommended to use TABLE tag + CSS style layouthtml web page code compression table tag layout table
Similar to this list Table table, it is recommended to use the table tag layout
Webpage GZIP Compression
It is recommended to set the webpage Gzip compression function on your own server.
1. What are the benefits of opening GZIP?
Answer: After Gzip is turned on, the data output to the user's browser will be compressed, which will reduce the amount of data transmitted through the network and increase the browsing speed.
2. How to enable the Gzip compression function of IIS:
Answer: First, if you need to compress static files (HTML), you need to create a directory on the hard disk and give it "IUSR_ Write permissions for the user "Machine Name". If you compress dynamic files (PHP, asp, aspx), there is no need, because its pages are dynamically generated every time and will be given up after compression. Then in the IIS manager, right-click on "Website" - Properties, not a certain site below, but the entire website. Enter the "Services" tab and select Enable dynamic content compression and static content compression. Then select the server extension under the website and create a new server extension. The name doesn't matter, the path to add the file below is: c:\windows\system32\inetsrv\gzip.dll, and then enable this extension. At this time, static content can be compressed, but for dynamic content, aspx files are not within the compression range. Because the default compressible file does not have this extension. And you can't find a place to add an extension in the management interface. At this time, you can only modify its
config file. There is a MetaBase.xml file under c:\windows\system32\inetsrv\. You can open it with Notepad and find IIsCompressionScheme. There are three sections with the same name, namely deflate, gzip, and Parameters. Don’t worry about the third section. The two paragraphs have basically the same parameters. Add a line of aspx below the parameter HcScriptFileExtensions in these two paragraphs. If you have other dynamic programs to compress, add them here. HcDynamicCompressionLevel is changed to 9, (0-10, 9 is the most cost-effective one). Then you need to restart the IIS service to experience the speed after compression. I believe you have mastered the methods after reading these cases. For more exciting information, please pay attention to other related articles on the php Chinese website!
Related reading:
The above is the detailed content of How to optimize HTML web pages. For more information, please follow other related articles on the PHP Chinese website!