问题
What is the best practice to use when swapping an image on a webpage? Altering the image source or just showing/hiding multiple images on the page?
回答1:
you have to choose in order to balance speed, with your two options:
Altering the image source
this way, the page will load faster because it only gets the visible images but it will take a little longer to show the new image when you change src attribute
just showing/hiding multiple images
this way, you are loading all the images on page load which will make it slower on loading and faster on swapping the images
回答2:
At the load time, multiple images will slow down the webpage, but at the execution time, I think it will be fastest to show/hide the images
来源:https://stackoverflow.com/questions/11938062/is-it-faster-to-swap-an-img-src-or-show-hide-multiple-images