Optimizing Assets with Base64
Base64 encoding allows you to embed image data directly into your HTML, CSS, or JSON files as text. This eliminates the need for a separate HTTP request to fetch the image file.


Pros & Cons
Advantages
- Fewer HTTP Requests: Speeds up page load by reducing the number of round-trips to the server.
- Single File: Easy to share or store as everything is contained in one text string.
Disadvantages
- Larger Size: Base64 strings are roughly 33% larger than the original binary file.
- No Caching: The image cannot be cached separately by the browser; it reloads every time the HTML/CSS reloads.
How It Works
Base64 encoding takes binary data (like an image) and translates it into a set of 64 ASCII characters (A-Z, a-z, 0-9, +, /). This ensures the data remains intact during transport over protocols that are designed to handle text.
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==


Learn More
Read more about Data URLs and when to use them.