在CSS中使用图像文件与数据URI [英] Using an image file vs data URI in the CSS

查看:99
本文介绍了在CSS中使用图像文件与数据URI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试确定包含我编写的脚本所需图像的最佳方式。

I'm trying to decide the best way to include an image that is required for a script I've written.

我发现这个网站它让我考虑尝试这种方法将图像包含为数据URI (由 RFC 2397 )因为它太小了 - 它是一个1x1像素的50%不透明度png文件(用于背景) - 它最终为2,792字节作为图像,而3,746字节作为CSS中的文字。

I discovered this site and it made me think about trying this method to include the image as a data URI (defined by RFC 2397) since it was so small - it's a 1x1 pixel 50% opacity png file (used for a background) - it ends up at 2,792 bytes as an image versus 3,746 bytes as text in the CSS.

那么这会被视为良好做法,还是会不必要地混乱CSS?

So would this be considered good practice, or would it just clutter up the CSS unnecessarily?

推荐答案

我认为你不会获得太多......如果它是文件图像,浏览器可以缓存它。除非你真的需要它,否则我不会费心去做它。

I don't think you will gain much... and if it is a file image, the browser can cache it. I wouldn't bother doing it with CSS unless you have a real need for it.

这篇关于在CSS中使用图像文件与数据URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆