Blob URL vs Data URL
Two ways to reference file data in a browser — similar in appearance, completely different in mechanism. This article explains the difference and helps you decide which to use.
What Are They?
Data URL
data:image/png;base64,iVBORw0KGgo…The file's complete data is Base64-encoded and written directly into the URL. The URL itself is the data — you can copy it, paste it, store it in a database, or embed it in HTML or CSS.
Blob URL
blob:https://example.com/550e8400-e29b…A temporary reference the browser creates for a Blob or File object in memory. The URL contains no data — it is just a pointer, valid only in the current page.
Side-by-Side Comparison
| Aspect | Data URL | Blob URL |
|---|---|---|
| Format | data:image/png;base64,iVBOR... | blob:https://example.com/abc-123 |
| Contains data? | Yes — data is encoded in the URL | No — it is a reference to browser memory |
| Shareable / copyable? | Yes — the URL itself is the data | No — only valid in the current page |
| Memory usage | High — Base64 string ≈ 1.33× file | Low — just an internal reference |
| Large file support | Poor — size bloat + browser slowdown | Good — works at any size |
| Lifetime | Permanent (as long as the string exists) | Expires on page close or revokeObjectURL() |
| Embed in HTML / CSS | Yes — inline directly | No — invalid after page refresh |
| Requires manual cleanup | No | Yes — call revokeObjectURL() |
When to Use Each
Use Data URL when:
- Embedding small images in HTML / CSS (< 5 KB)
- Embedding images in HTML emails (Blob URL not supported)
- Inlining a small @font-face font
- Sending small attachments in a JSON API
- File data that needs to be copied, stored, or transmitted
- Inlining SVG favicons in <link>
Use Blob URL when:
- Previewing uploaded images or videos in the browser
- Triggering file downloads (<a download>)
- Previewing a canvas export
- Temporarily displaying the result of a large file operation
- MediaSource API for streaming playback
- Temporary URLs while working with Blob data
Code Examples
input.addEventListener('change', (e) => {
const file = e.target.files[0]
const url = URL.createObjectURL(file)
// Preview image
img.src = url
// Trigger download
const a = document.createElement('a')
a.href = url
a.download = file.name
a.click()
// Release when done
URL.revokeObjectURL(url)
})const reader = new FileReader()
reader.onload = (e) => {
const dataUrl = e.target.result
// Embed in HTML, CSS, JSON, or store
img.src = dataUrl
// dataUrl: "data:image/png;base64,iVBOR..."
}
reader.readAsDataURL(file)Remember to Release Blob URLs
Every call to URL.createObjectURL() creates an internal reference to the Blob data inside the browser. Even if the JavaScript variable has been garbage collected, the reference remains and the data cannot be freed.
Call URL.revokeObjectURL(url) at the right moment to release the reference:
| Scenario | When to revoke |
|---|---|
| Triggering a download | Immediately after clicking (after the <a> click event) |
| Image preview | When the user selects a new file, or when the preview component unmounts |
| Video preview | When video playback ends, or when the component unmounts |
| React component | In the cleanup function of useEffect |
Related Tools
Data URI Generator
Upload a file and get a complete Data URL with the correct MIME type.
Base64 to File
Decode a Data URL or Base64 string back to a file and download it.
Base64 to Image
Decode Base64 or a Data URL to an image and preview or download it.
File to Base64
Convert any file to a Base64 string or Data URL.
Frequently Asked Questions
What is the core difference between a Blob URL and a Data URL?
A Data URL encodes the file data into the URL itself (as a Base64 string) — it can be copied, transmitted, and stored persistently. A Blob URL is a temporary reference to Blob data in browser memory; the URL contains no data, is only valid in the current page, and expires when the page is closed.
Which is better for previewing images?
Blob URL is better. URL.createObjectURL() does not copy the data, so memory usage stays close to the original file size. FileReader.readAsDataURL() generates a Base64 string roughly 1.33× the original file size. The difference grows with file size.
Why can HTML emails only use Data URLs?
Email clients render HTML outside the browser context and cannot resolve Blob URLs (the blob: protocol is browser-private). Data URLs embed the image data directly in the HTML, so an email client can parse them independently — making them the only option for embedded images in email.
What happens if I never call revokeObjectURL?
The browser holds an internal reference to the Blob data indefinitely. Even after the JavaScript variable is garbage collected, the data cannot be freed. If a page creates many Blob URLs without releasing them, memory grows continuously until the page is closed.
Can I store a Blob URL in a database or localStorage?
No — there is no point. A Blob URL is only valid within the lifetime of the page that created it. Even if the URL string is preserved, the data it pointed to is gone after a page refresh. For persistence, use a Data URL or upload the file to a server first.
How do I convert a Blob URL to a Data URL?
Fetch the Blob URL to get the Blob, then use FileReader.readAsDataURL(): fetch(blobUrl).then(r => r.blob()).then(blob => { const reader = new FileReader(); reader.onload = e => console.log(e.target.result); reader.readAsDataURL(blob) })