Don’t use Base64 encoded images on mobile.

Jasper Morgan
Mar 8, 2018 · 4 min read
Image for post
Image for post
Photo by Chris Ried on Unsplash

Recently I came across an API from a client that delivered images in part of the response as Base64 encoded strings. My immediate reaction was “Bad idea”.

Here are the concerns we discussed which led the API to be changed to use URIs for images instead.

At the end I consider a couple of cases where Base64 encoding could be a good option.

API response payloads are large.

By including the data for every image in the API response, the response payloads started to get in the MB range.

Over mobile networks, additional payload sizes matter. Larger payloads also mean more time for responses to be in flight and more time for (mobile) network drops.

Base64 images are bloated.

As well as a larger overall payload size, the size of the Base64 encoded image is approximately 30% larger than the original binary image.

With gzip compression this bloat can be avoided if the alternative is raw binary images. However sizes will still be larger if the binary images are compressed. At scale these things start to matter. (See some stats here:

User Experience is negatively impacted .

By including all image data together in one API response, the app must receive all data before drawing anything on screen. This means users will see on-screen loading states for longer and the app will appear sluggish as users wait.

Alternatively, when an app loads images separately from the API payload, the app can show the data from the API and then progressively load the images. The effect is a more responsive app that feels faster to users.

CDN caching is harder.

Contrary to image files, the Base64 strings inside an API response cannot be delivered via a CDN cache. The whole API response must be delivered by CDN.

An API caching strategy can be straightforward if the API is not dynamic, e.g. personalised to each customer. However, with dynamic APIs there is quite a bit of architectural complexity compared to delivering static assets such as images via a CDN.

Image caching on the device is no longer possible.

Typically apps will cache images so they must not be repeatedly re-fetched. However, if images are sent to the device as Base64 encoded strings every time within an API response, any caching capabilities on the device becomes irrelevant.

Caching on the device represents quite a major improvement for app performance, especially as app-level caching is very easy with mature libraries such as Picasso for Android ( or Kingfisher for iOS (

Content management becomes harder.

Most content management tools handle images as binary files. To create Base64 encoded representations there will probably need to be some post-processing following image upload. This might require some custom logic that is hooked into your content management system. You will also need to watch for any adverse effects on database performance depending on your storage engine.

If you are storing large volumes of images, then you are shifting a bulk of storage to a structured datastore (i.e. a database). With cloud computing, file-based storage is very cheap and there might be a cost implication for taking a Base64 approach to images.

Does Base64 encoding images ever make sense on mobile?

Yes, it can. Here are a couple of ideas.

The Dropbox team make a compelling case for using Base64 encoding to effectively stream thumbnails for an image gallery: The argument is that when loading many small images, the overhead of HTTP requests becomes a factor. Key to their approach is using chunked transfer encoding which effectively streams the response so the client can process the Base64 encoded images as they arrive across the wire. Also significant is that the use-case is centred around fetching images — in other words this isn’t for delivering images as part of a mixed content API.

Another use could be delivering slow-changing non-personalised data that includes small images. For example, loading partner logos, map pin images or category icons during app launch/restore. APIs delivering this type of data can easily be cached on a CDN and versioned to trigger updates. Whether the gains for slow-changing data warrant the development effort is another matter.

There are likely to be other scenarios where Base64 encoded images are a smart approach. For me, these are going to be special cases. Most of the time, simply loading images via a URI is the way to go.

Jasper Morgan

Written by

CEO of Snapp Mobile, an engineering and design team with a passion for everything mobile and fintech. Based in Munich, Berlin and London.

Snapp Mobile

Snapp Mobile Engineering and Design Blog

Jasper Morgan

Written by

CEO of Snapp Mobile, an engineering and design team with a passion for everything mobile and fintech. Based in Munich, Berlin and London.

Snapp Mobile

Snapp Mobile Engineering and Design Blog

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store