简体   繁体   中英

How to load image in javascript without put it in the cache

I would like to load image in javascript, like that :

var img = new Image();
img.src = "http://www.myimage.fr/myimage.jpg";

But i would like the image don't go in the browser's cache when she is loaded. It's important to keep this url, i don't want to set any parameter like a timestamp to the url.

Any idea ?

Many thanks

To do this you'll need your web server to output the appropriate headers along with the response.

You can instruct the browser to not cache the resource by setting these headers:

Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0

Since this is a static file you are serving (an image) you'll have to configure your web server to do this for you, based on the filename or the extension. What web server is serving your website?

<head>   
<meta charset="utf-8">   
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
-----
</head>

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