使用< a href ="数据安全吗? ...">显示图像? [英] Is it safe to use <a href="data; ..."> to display images?

查看:131
本文介绍了使用< a href ="数据安全吗? ...">显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道可以像这样在HTML页面中嵌入图像,而不是链接到单独的图像文件:

 < a href =data:image / png; base64,...(blah blah base64-encoded png goes here)...
width =70height =38alt =使用base64编码嵌入图片!>< / a>

这是否安全,因为所有现代浏览器都可以查看图像因为我坚持常见的格式,如PNG / JPG?是否有任何缺点,除base64编码的图像增加图像的大小?



谢谢。

解决方案

是的,这是安全的 - 所有主流浏览器都支持数据URI方案

其中一个缺点是,如果您在页面中多次使用相同的图片,它会被编码几次,然后下载一次。



另一个是由某些浏览器施加的大小限制(IE 8只允许高达32k)。

您也可以在CSS中使用它以缓解下载问题。


I've learned that it's possible to embed an image in an HTML page like so, instead of linking to a separate image file:

<a href="data:image/png;base64,...(blah blah base64-encoded png goes here)..."
  width="70" height="38" alt="image embedded using base64 encoding!"></a>

Is this "safe", as in will all modern browsers be able to view the image, as long as I stick to common formats like PNG/JPG? Are there any downsides, other than base64-encoding the image increasing the image size by a bit?

Thanks.

解决方案

Yes, this is safe - all major browsers support the data URI scheme.

One downside is that if you use the same image a number of times in the page, it will be encoded several times vs downloaded once.

Another is the size limit imposed by some browsers (IE 8 only allows up to 32k).

You can also use this in CSS to mitigate the download issue.

这篇关于使用&lt; a href =&quot;数据安全吗? ...&QUOT;&GT;显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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