Is it safe to use lt;a href=quot;data; ...quot;gt; to display images?(使用 lt;a href=quot;data; 是否安全?...gt;显示图像?)
问题描述
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="aW1hZ2UgZW1iZWRkZWQgdXNpbmcgYmFzZTY0IGVuY29kaW5nIQ=="></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.
这篇关于使用 <a href="data; 是否安全?...">显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 <a href="data; 是否安全?...">显示图像?
- Fetch API 如何获取响应体? 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- addEventListener 在 IE 11 中不起作用 2022-01-01