Data URI
Data URI (Inline Data Scheme)
A URL scheme that embeds file content directly within HTML, CSS, or JavaScript using the format data:[mediatype][;base64],data, eliminating the need for a separate HTTP request to fetch the resource.
技術的詳細
Data URIs follow the syntax: data:[
例
```javascript
// Encode string to Base64
const encoded = btoa('Hello, World!'); // 'SGVsbG8sIFdvcmxkIQ=='
// Decode Base64 to string
const decoded = atob('SGVsbG8sIFdvcmxkIQ=='); // 'Hello, World!'
// File to Base64 Data URI
const reader = new FileReader();
reader.onload = () => console.log(reader.result);
// → 'data:image/png;base64,iVBORw0KGgo...'
reader.readAsDataURL(file);
```