Using JS to implement the image cache

Source: Internet
Author: User

Web pages use HTML elements to embed images, like all HTML elements, elements can be manipulated by scripts (setting the SRC attribute of an element, pointing it to a new URL causes the browser to load and display a new picture). In order for the picture to be cached, the client JS defines an API that first uses the image () constructor to create an offscreen picture object, and then sets the desired URL for the SRC attribute of the object, which is not visible because the picture element is not added to the document. However, the browser will still load the picture and cache it.

// picture paths that need to be preloaded are stored in the array var imgsrc=[    "Images/34.jpg",    "Images/32.jpg",    "Images/33.jpg" ]; // initializing an Image object var New Image (); // iterates through the path of an array, preloaded to the client  for (var i = 0; i < imgsrc.length; i++) {    = imgsrc[i];}

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.