Current location - Health Preservation Learning Network - Slimming men and women - How to optimize website code
How to optimize website code
1, table label reduced

Table label is the most common code form in most online websites at present. The fundamental reason is that table is faster when building a website, but it also affects the post-optimization of the website.

Compared with the simple code website with div+css layout, it takes up more space. Therefore, when building a website, use tables as little as possible, and even if tables are to be used, use nested tables as little as possible to avoid garbled codes.

2. Code comments are omitted

Many programmers are used to writing a note that others can't understand. These codes are often for the cooperation of several programmers and are of no use to outsiders and search engines. On the contrary, it will bring some trouble to search engine spiders.

When we open the page code, we often see some comment codes, which are comments made by programmers to express the meaning of the code. In fact, these openings are unnecessary, because for search engines, they have no meaning, but will increase the capacity of page code, which is not good for the website. Why don't you just omit it?

3. Clear the redundant code in the page

Some websites think that there are many blank codes on the page because of the code writing habits of the producers, such as blank codes, codes with repeated definitions of styles and fonts. Don't underestimate these small codes, accumulating too much will make our website extremely bloated.

Many websites use DIV+CSS, which defines the font, color and page layout of the text, but in other parts of the website, the font is redefined with style and font, which can be simplified without repeated definition.

4. Convert the html control mode into CSS control.

Many web designers are used to controlling the content in tags. For example, in the img tag, the size of the picture is controlled by the width and height, and these codes are converted into external CSS as much as possible to make the webpage code finer.

5. Cache static resources

By setting the browser cache, the infrequently updated files such as css and js are cached in the browser, so that when the same visitor visits the website again, the browser can get css and js from the browser cache instead of reading them from the server every time, which speeds up the opening of the website to some extent and saves the server traffic.

6. Web page compression technology

As far as web page compression is concerned, I believe all webmasters are familiar with it. The main purpose is to enable server Gzip to compress pages and reduce the volume of elements, thus reducing data transmission and improving the loading speed of web pages. This function needs the support of the server. Gzip compression can generally compress web pages by 30%-80%, which is an important optimization effect.