How Embedding Base64 Images Affects Page Load Performance
This article examines the trade‑offs of converting image resources to Base64 and embedding them directly in HTML or CSS, measuring load and render times with the Navigation Timing API across desktop and mobile browsers, and presents real‑world test results.
Embedding image resources as Base64 strings lets developers place them directly in HTML or CSS, eliminating separate HTTP requests and potentially speeding up the first paint. However, the resulting HTML/CSS files become larger, which may impact parsing and rendering performance.
Measuring Performance with Navigation Timing
The article uses the Navigation Timing API to capture key timestamps during page load. The relevant properties are accessed as follows:
var timing = window.performance.timing;
// timing.domLoading – when the browser starts parsing the first byte of the HTML document
// timing.domInteractive – when the HTML and DOM are fully parsed
// timing.domContentLoadedEventStart – when DOM parsing finishes and resource loading begins
// timing.domContentLoadedEventEnd – when all resources (e.g., scripts) have finished loading
// timing.domComplete – when the entire page, including images, is fully loaded and readyFrom these timestamps two derived metrics are calculated:
build = timing.domComplete - timing.domContentLoadedEventStart; // time between resource loading start and final render
complete = timing.domComplete - timing.domLoading; // total time from start of data receipt to full renderTest Scenario: Base64 Image in CSS
A 50 KB JPG image is encoded to Base64 and embedded in a CSS file, then applied as a background to 135 DOM elements, simulating a sprite‑like usage. The test environment includes:
Mac OS X El Capitan with Chrome 48
iPhone 6 Plus iOS 9
Meizu Note Android 4
Images illustrating the setup:
Navigation Timing values are taken from Chrome’s official documentation; results may differ on other platforms. In Android + WeChat the measured build time was consistently 0 ms, likely due to a different rendering mechanism.
Results
With caching disabled, the measurements were:
build: 150 ms
complete: 200 ms
These figures are influenced by network conditions and should be used for comparative purposes only.
Conclusion
Base64‑embedding can reduce request overhead and improve first‑paint speed, but the increased payload size may affect parsing and overall rendering time, especially on lower‑end devices or browsers with different rendering pipelines. Developers should benchmark on target platforms before adopting this technique.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Aotu Lab
Aotu Lab, founded in October 2015, is a front-end engineering team serving multi-platform products. The articles in this public account are intended to share and discuss technology, reflecting only the personal views of Aotu Lab members and not the official stance of JD.com Technology.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
