This can easily be verified using Firebug (under Net), Chrome Developer Tools (under Network), Fiddler or any other HTTP sniffer you prefer.
If you put the image in CSS as background-image, the image will only get downloaded when that class is actually used and visible. If you put it in an img
it'll be downloaded immediately and will block rendering even if it's invisible.
In the end they are both as fast if you are counting the speed at which the image loads per se. The real question is if the perceived performance is better as the order at which the image gets downloaded might be different depending on where you place your element.
I would worry more about the other aspects though. Having the image as a background-image means:
- The image is not a content
- It is not printable
- You can use a sprite to reduce the number of HTTP requests (thus improving performance)
- It is slower to animate background-image than img
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…