DEV Community

Victor Magarlamov
Victor Magarlamov

Posted on • Edited on

1

Using Base64 encoded image

The window.onload event does not occur until resources are fully loaded. And often images are the biggest part of resources.

The total resource loading time consists of:

  • waiting for a server response,
  • data loading time,
  • byte analysis,
  • byte conversion to an object.

Encoding an image in Base64 format converts binary data into ASCII string format. Loosely speaking, we can convert an image to text using this process. This allows us to inline images as text on the page and get rid of the steps: "waiting for a server response" and "data loading time".

I use this technique for small images that are used as logos, icons or background images for buttons, panels and etc.

Downsides of the inline images

  • Converting images to base64 results in a 30% increase in size.
  • Size of HTML page increases.

How to convert

The easiest way is to use online converters. For example base64-image

How to use

You can set the string as the value of the src property or as css background.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay