Technical Analysis of Famous Sites-discussion on the effect of delayed image loading on tudou.com Homepage

Source: Internet
Author: User

 

I often go to Tudou network and find that the function of loading images on the Tudou homepage is very interesting. The thumbnails of all videos on the Tudou homepage from the "Entertainment" section are not loaded after the page is opened, instead, when you drag the scroll bar to the "Entertainment" section, you start to load the image. The advantage of this is, of course, that if a user does not need to view the following content, all the image requests are removed, which is helpful for reducing the server pressure.

I often go to Tudou network and find that the function of loading images on the Tudou homepage is very interesting. The thumbnails of all videos on the Tudou homepage from the "Entertainment" section are not loaded after the page is opened, instead, when you drag the scroll bar to the "Entertainment" section, you start to load the image. The advantage of this is, of course, that if a user does not need to view the following content, all the image requests are removed, which is helpful for reducing the server pressure.

 

Implementation:

 

In fact, the implementation principle of Tudou is very simple,

 

1. First, set the srcof all images with delayed delay to the connection (sprite.gif) of the same small image, and put the connection of the real image into the alt attribute of the image.Code:

<A class = "inner" target = "new" Title = "the heaviest street dance runners and softest street dance runners in history" href = "http://www.tudou.com/programs/view/Utmt1_6Z-lU/">

</A>

 

2. Bind the window. scroll event, reset the SRC value of all images whose classes are lazyimg in the event, and find the following js on the Tudou homepage:

VaR o = function (){

VaR S = tui. Pos. scrolltop (), q = C;

If (Q. Box [0]) {

VaR r = Q. Box. offset (). Top;

If (R-S> 0 & r-TUI.pos.windowHeight () <s ){

Q. INIT ()

} Else {

Q. Stop ()

}

}

If (! H | S <590) {return true}

Tui. widget. quickplaylist. Load ();

H = false

};

O ();

$ (Window). BIND ("scroll", O );

 

I have not followed the implementation of The tui. widget. quickplaylist. Load () method. The JS of Tudou is compressed and obfuscated. It looks tired, but you can understand the principle.

 

Instance:

As mentioned above, it is more practical to come to an instance.

 

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml"> 

 

 

Copy the above Code to the local run to see the effect.

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.