开发者

which technique show image in css is faster?

开发者 https://www.devze.com 2023-01-15 00:22 出处:网络
technique 1 .realimage {background: url(\'data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/

technique 1

.realimage {background: url('data:image/png;base64,
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/
//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U
g9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC')}

technique 2

.realimage {background: url('http://..test.jpg);

Questions

  1. If I need to show multiple same image on the same page, I think technique 2 should be faster right? because subsequent to开发者_如何学Go retrieve image will be from browser cache?

  2. If I need to show multiple same image on the different page, I think technique 2 should be faster right? because subsequent to retrieve image will be from browser cache?


My main points against technique 1 would be:

  • data URIs aren't that widely supported (I'm looking at IE in particular, of course)
  • the same image used in different CSS files causes unnecessary overhead
  • CSS files become unnecessarily large

Technique 2 should be preferred. Initially it causes an additional HTTP request, but each subsequent use of the same URL will be cached, regardless of where it's used (HTML, CSS, Javascript).

0

精彩评论

暂无评论...
验证码 换一张
取 消