0

Do browsers (chrome, IE7+) cache image data, after first time downloading the image?

function updatePhoto(url) {
  document.getElementById("bigImage").src = url
}

I have the following event handler function, which updates big image's src attribute when user clicks a thumbnail. I don't want to do the heavy lifting each time user clicks a thumbnail. Do browsers retrieve the data from cache in the case when src attribute is directly changed with javascript? Is it certain, or is there some technique to ensure to use the cached data?

2
  • It depends on the headers sent from the server for the HTTP request for the image (note: not the page). In general the browser is very aggressive and will cache almost anything it can. The usual problem people have is how to avoid the browser caching something. Commented May 22, 2017 at 9:02
  • Most browsers would cache the image - a lot of people used to use js to preload their images by setting the src of an image object - stackoverflow.com/questions/10240110/… Commented May 22, 2017 at 9:04

1 Answer 1

2

Do browsers (chrome, IE7+) cache image data, after first time downloading the image?

Subject to the normal rules of HTTP caching. Yes, of course.

Do browsers retrieve the data from cache in the case when src attribute is directly changed with javascript?

Of course (subject to the normal rules of caching and assuming it was cached in the first place).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.