简体   繁体   中英

Javascript reusable images caching?

Is it possible to avoid asking server for 304 header for reusable images via jQuery or clean javascript?

Thanks ;)

The HTTP image caching is done between webserver and webbrowser. You won't be able to influence it with JavaScript, as the expiration/modification headers are HTTP headers, which will be handled by the browser, and not passed to JavaScript.

You could try saving the images as javascript objects, ie.

var image = new Image();
image.src = "/test.png";

You can inject this object in the DOM as many times as you want and it will only request the image once.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM