简体   繁体   English

CSS精灵与数据URI

[英]CSS sprites vs data URIs

I've heard a lot about the importance of using sprites in order to get your request count down. 我已经听到很多关于使用Sprite来减少请求数量的重要性的信息。 But my thinking is that rather than use sprites, you can use URIs to accomplish the same thing, and much easier (no sprite creation needed). 但是我的想法是,您可以使用URI而不是使用Sprite来完成同一件事,并且更加容易(不需要创建Sprite)。

Is it better to use sprites or uris? 使用sprites或uris更好吗?

Base64-encoded data is about 1/3 larger than raw bytes, so on pages where downloading all the image data takes more than three times as long as making a request, CSS sprites are superior from a performance basis. Base64编码的数据比原始字节大大约1/3,因此在页面上下载所有图像数据的时间是发出请求的三倍以上,因此CSS Sprite从性能上来说是优越的。

Also, inline data URIs make the file itself take as long to load as the actual data plus the base64-encoded images. 此外,内联数据URI使文件本身的加载时间与实际数据以及base64编码的图像一样长。 If the data URIs are on your actual HTML page, that means rendering stops and waits for the image to load. 如果数据URI在您的实际HTML页面上,则表示渲染停止并等待图像加载。 If the data URIs are in your stylesheet, that means any rules after the data URI have to wait for it before they can be processed. 如果数据URI在样式表中,则意味着数据URI之后的任何规则都必须等待它才能被处理。 On the other hand, with a sprite file, the images can load concurrently with your other resources. 另一方面,使用Sprite文件,图像可以与其他资源同时加载。 That may be worth the cost of one extra request, especially when you factor in the base64 penalty. 这可能值得一个额外的请求,特别是当您考虑到base64罚款时。

我想如果对IE5、6和7的目标很重要,那么对IE5、6和7的支持将是一个很好的理由。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM