Statistical code traps virtually affect the speed of the Internet

Source: Internet
Author: User

Http://www.yilingsj.com/xwzj/2016-08-30/435.html

Talking about the site statistics Code , a little bit of crossing will certainly think of a stack of statistical platforms, such as: Baidu statistics ,51.la statistics , Friends of the League statistics and so on. There are traps in these statistical codes, too!

First, review the optimization of web site common sense

Generally speaking, we will put the JS code before the closed </body> , because the advantage is: the page is loaded from the top down, JS put the bottom is the last load, which can improve the speed of opening the page.

Although the reason crossing all understand, not is will js put the bottom well, have what to say. Can crossing really understand???

Second, the trap one: Statistics code put the footer but still appear in the head

If crossing is a webmaster, you can check your website to see if the statistics code has not appeared in head . Well, the art is not suspense, speak directly with the code! After all, the language is not very good expression, you crossing can look at the picture carefully!

2.1, Baidu Statistical code

The following is the latest Baidu statistics code, if crossing need Baidu statistics, can be obtained from Baidu official website, login address: sitecenter.baidu.com/sc-web/  .

2.1.1, sample code

    1. <script>
    2. var _hmt = _HMT | | [];
    3. (function () {
    4. var HM = document.createelement ("script");
    5. HM.SRC = "//hm.baidu.com/hm.js?......";
    6.   var s = document.getelementsbytagname ("script") [0];
    7.   S.parentnode.insertbefore (hm, s);
    8. })();
    9. </script>

Crossing generated code will see a installation instructions, with a picture: You can see Baidu is advocating to put the code into the. If crossing is willing, follow Baidu said Operation Bar. Here is the art of this tutorial!

If crossing put the generated code </body> in front of it, it's common sense that the statistical code would be in our expectation, and that's not the case! Why???

2.2. Cause analysis

I wonder if crossing has noticed the yellow highlights in the art code, there are two lines:
The first line is to find the node ;
The second line is the insertion of the content before the node .
Then the problem is here! If the crossing is written in the <script> label, Baidu's statistical code will rub a bit before running to this <script> label. With a picture: understand???

2.3. Solutions

Now that we know the reason, the solution is very simple. The solution also has two steps:
First step: Replace the node ,
Step two: Append content.

2.3.1, modifying code

    1. var s = document.getelementsbytagname ("body") [0];
    2. S.appendchild (HM);
    3. })();
    4. </script>

The above yellow highlighting for the modified part, we will refresh the next page to see the effect of it, with the picture: how, so good!

For other platform statistics code, the modification method can refer to the above 2.3.1.

Let's say the second trap in the statistics code.

Third, trap two: Statistics code pictures Slow down the speed of the Internet

The following is an example of 51.la.

The webmaster who used the statistic code should know that the statistic code has many kinds of styles, such as: Picture, text form and so on. Let's get a 51.la! Login Address: www.51.la with map: How, look at a lot of it, there is always a suitable for their own.

Some time ago, the art of the site due to a variety of factors, always do not open or open very slowly, and later saw in addition to a number of factors, statistical code is also a part!

Let's take a look at the normal loading speed of the icon, with the picture: you can see that the icon load time above 1min, although these are just a small little icon .....

During that time, 51.la such an icon, sometimes loading a few minutes have not finished loading, which also navigated the page content can not be displayed properly. Later in the text, speed quickly, but still have problems. And this problem is the statistical code itself, such as 51.la: web.51.la:82/go.asp? This request is more time-consuming, but these are the problem of the statistical platform, we can not solve.

Iv. final

Well, about the statistical code, universal existence of the two trap art has been demonstrated and provide a solution to the method, you can view the webmaster's own website, if you feel that the art is not reliable, their own use of the test time to know, after all, dry this line is to rely on data to speak!

In addition to the statistical Code, the various platforms share code , push code , and so on more or less exist above the trap phenomenon provided above. The most obvious is Baidu home Baidu push send ! As for how to solve, presumably crossing should learn it!

Statistical code traps virtually affect the speed of the Internet

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.