Answer the question
In order to leave comments, you need to log in
Track image loading time?
Hello. vuejs app.
Functionality on the site: when you click on the button, a link to the selected image is inserted into the img tag.
<a href="#" data-img="http://site1.ru/img1.jpg" @click="selectImage">Картинка 1</a>
<a href="#" data-img="http://site1.ru/img2.jpg" @click="selectImage">Картинка 2</a>
<img v-if="selectedImage" :src="selectedImage">
...
selectImage(e) {
this.selectedImage = e.attr["data-img"]
}
...
Answer the question
In order to leave comments, you need to log in
console.time('Image loading');
document.querySelector('img').addEventListener('load', function() {
console.timeEnd('Image loading'); //> Image loading: 1192.903076171875ms
});
var start = performance.now();
document.querySelector('img').addEventListener('load', function() {
var end = performance.now();
console.log(end - start); //> 13.999999999214197
});
img throws a load event after loading is complete. In selectImage we turn on "twist-twirl" (loading), in the load handler we turn off "twist-twirl"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question