Blank tags such as Img, Script, and Link can cause redundant page requests

Source: Internet
Author: User

Setting the img, script, and link tags in the page as empty links can cause excessive page requests, including IE, Firefox, chrome, and Safari! However, when the src and href values of the script and link are empty compared with img, no request is made in IE, whereas Chrome, Safari, and Firefox will have a redundant new request. The following describes in detail:

Analysis of empty img src
Whether writing in html or creating var img = new Image (); img. src = "";, will lead to more requests to your server. The specific request analysis is as follows:

In IE, this will request the directory of the current page once. If this empty src label appears in the http://js8.in/demo/a.html, it will cause a re-Request: http://js8.in/demo/
In Safari and Chrome, the current page is requested.
In versions earlier than Firefox 3.5, the problem is the same as that in Safari, but this BUG was fixed in Firefox 3.5.
In Opera, no additional requests are made.

In a website with a low access volume, it doesn't matter if you have another such request (or even double your website's browsing), but in a website with tens of millions or even higher access volume, this will significantly increase your server and bandwidth costs. Another risk is that a new request to a page may result in unintentional modification of user information, such as cookies or ajax operations.

You will never write such code?
I don't think so. This often happens accidentally, for example, the following php code:


You originally planned to read this src address from the server, but for some reason, this address has not been set, or the Code BUG causes the read to fail, and an empty src tag will appear.

Will empty src in other labels cause such a problem?
The good news is that only the image Tag in IE has this problem.
In Chrome, Safari, and Firefox, both <script src = ""> and <link href = ""> lead to a new request.

How can this problem be solved?
You can start from two aspects. First, try to avoid this bad programming method and avoid empty src labels. In addition, you can start from the server side and do not return anything to the client when discovering such meaningless requests.

<? Php
$ Referrer = isset ($ _ SERVER ['HTTP _ referer'])? $ _ SERVER ['HTTP _ referer']: '';
$ Url = "http: //". $ _ SERVER ['HTTP _ host']. $ _ SERVER ['request _ URI '];
If ($ referrer ==$ url ){
Exit;
}
?>

Link: http://www.js8.in/555.html

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.