Answer the question
In order to leave comments, you need to log in
Track the progress of downloading an image and at the same time preserve browser caching?
I know it's possible to programmatically load an image while keeping it cached by the browser like so:
let img=new Image()
img.onload=()=>imgFromDOM.src=url
img.src=url
var xmlHTTP=new XMLHttpRequest();
xmlHTTP.open('GET',url,true);
xmlHTTP.responseType='arraybuffer';
xmlHTTP.onload = function(e) {
var blob=new Blob([this.response]);
thisImg.src=window.URL.createObjectURL(blob);
};
xmlHTTP.onprogress = function(e) {
thisImg.completedPercentage=parseInt((e.loaded / e.total)*100);
};
xmlHTTP.onloadstart = function() {
thisImg.completedPercentage=0;
};
xmlHTTP.send();
Answer the question
In order to leave comments, you need to log in
That's it, I evolved to the realization that all this time I was trying to load images from third-party resources with XHR, which is prohibited in browsers, and I got an error instead of an image. Because my system, alas, is impossible to do, at least using only js, however, local images are indeed cached after XHR loading.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question