简体   繁体   English

Javascript可重用图像缓存?

[英]Javascript reusable images caching?

Is it possible to avoid asking server for 304 header for reusable images via jQuery or clean javascript? 是否有可能避免通过jQuery或干净的javascript向服务器请求304标头中的可重用图像?

Thanks ;) 谢谢 ;)

The HTTP image caching is done between webserver and webbrowser. HTTP图像缓存在Web服务器和Web浏览器之间完成。 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. 您将无法使用JavaScript对其进行影响,因为到期/修改标头是HTTP标头,它将由浏览器处理,并且不会传递给JavaScript。

You could try saving the images as javascript objects, ie. 您可以尝试将图像保存为javascript对象,即。

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. 您可以根据需要在DOM中多次插入此对象,并且该对象只会请求一次图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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