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="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.
这篇关于使用 <a href="data; 是否安全?...">显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 <a href="data; 是否安全?...">显示图像?
基础教程推荐
- Chart.js 在线性图表上拖动点 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 直接将值设置为滑块 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01