A data URI is a way to embed a file's contents directly into a URL. Instead of pointing to an external file (src="logo.png"), it inlines the file as Base64: src="data:image/png;base64,iVBORw0KGgo...". The browser decodes and renders it with no extra HTTP request.
canvas.toDataURL() returns a PNG as a Base64 data URI — useful for client-side screenshot or image generation tools.| Advantage | Disadvantage |
|---|---|
| No extra HTTP request (saves latency for tiny images) | 33% larger than binary (Base64 overhead) |
| Works offline and in sandboxed contexts | Not separately cacheable by the browser |
| No CORS issues | Bloats HTML/CSS file size — bad for large images |
| Good for email clients that block external URLs | Increases HTML parse time; not lazy-loadable |
Data URIs are a good choice for images under ~5 KB (icons, avatars, small decorative elements). For anything larger, serve the image as a separate file — CDNs, HTTP/2 multiplexing, and browser caching will outperform inlining. For SVGs specifically, inline the raw SVG markup rather than Base64-encoding it: it's smaller and remains accessible to CSS and JavaScript.
Your images are read locally by the FileReader API and never uploaded anywhere.