V
V
Valsin2020-06-21 20:06:24
JavaScript
Valsin, 2020-06-21 20:06:24

Why does onload fire only once after clearing the cache?

Hello, there is such a script waiting for the image to be loaded

let img = document.querySelector('.image');
    img.onload = someFunc;


The problem is that the someFunc function is triggered only after the cache is reloaded. I believe that the fact is that Google Chrome caches the image and does not download it a second time.
Actually the question itself is how to work out onload after each page reload
(onload is needed, because ie does not want to work without it)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Seanyr, 2020-06-21
@Valsin

In short, I advise you to use jquery if compatibility is important, or you can do additional processing under ie, like this:

if (img.addEventListener) {
  image.addEventListener('load', someFunc);
} else {
  // для IE
  img.attachEvent('onload', someFunc);
}

And at the expense of the cache, read here . Everything is quite simple there, but now there is no time to paint. Maybe later I will add

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question