Optimising Images in Web and Native

Rate this content
Bookmark

It's safe to say that a lot of websites and apps these days are heavily reliant on images: product images, avatars, social sharing. With continued technological advances, the variety of device sizes you need to support keeps growing. How exactly are we to make the same page look great and feel performant on both a 16'' MacBook Pro with a retina display as well as a small 5 year old Android phone? We will look at some of the modern approaches to tackle just this problem on web and native - as well as what happens if you don't.

Kadi Kraman
Kadi Kraman
21 min
02 Jun, 2023

Comments

Sign in or register to post your comment.

Video Summary and Transcription

This Talk focuses on optimizing images for mobile and web. It emphasizes the importance of image dimensions in optimizing images and shares a story about crashes encountered in a mobile app due to heavy image content. The Talk discusses image rendering and sizing, using dimensions and pixel density, optimizing images for different devices and screen sizes, and the importance of image size and format optimization. It recommends tools like Cloudinary for image optimization.

1. Introduction to Optimizing Images

Short description:

Hi, my name is Kati Cremmann. I'm the lead developer of ReactJS. This is a speech about optimizing images for mobile and web. Optimizing images involves optimizing the content and the file size. For content optimization, aspect ratio is crucial. For file size optimization, we need to minimize the assets.

Hi, my name is Kati Cremmann. I'm the lead developer of ReactJS. And this is a speech from our new guest speaker, Kati. Hello! Thank you. You are my true friends. Thank you, everyone, who stayed just before lunch. I will try to keep it brief. Thank you for that intro, Janne. It was amazing, as always.

So, hi, my name's Kati Cremmann. I'm the director of engineering for mobile at the moment at Promotable. We're an amazing JavaScript consultancy. We build things in React and React Native. And a lot of these things include images, which brings us to the topic of my talk, which is about optimizing images for mobile and web.

So, what exactly do I mean by optimizing images? You can kind of think of it in two ways. One way is around optimizing the content of the image. So, optimizing the cropping of the image. Are you going to use portrait or landscape? Where do you want to fit the subject of the image so it fits best the position you have on the screen? So, to give you an example, so, on the left, we have an original image, which is in portrait mode. And say that our goal was to use it as a hero image on a website or maybe like a banner image on Twitter. This is not an optimal image for this use case, because, as you can see, there isn't really a good way to crop it, so we end up with half a child. But this talk is not about cropping. If it was about cropping, the TLDR at the end would be to use an aspect ratio. So, as developers, we are not usually in charge of actually taking the images and positioning the images. That's for a job for the experts. But the way that we communicate what we need, the positions that we have on the screens, are using an aspect ratio. So, an aspect ratio is a ratio between the width and the height of an image. So, rather than saying, I need an image that's 750 by 500, you can tell your designer or a photographer that you need an image with an aspect ratio of three to two, and they can then give you the highest quality image they're able.

The other way to look at images is to look at the file size. So, this is something that we are more used to optimizing, because we are well aware that when we are rendering a mobile app or rendering a website, then the user has to download all the assets from whatever server before we can display them. So, we want to have these assets, images, JavaScript bundles, CSS, as small as possible.

2. Importance of Image Dimensions

Short description:

The width and height of an image matter a lot in optimizing images. As technology advances, the problem of image optimization keeps getting harder. For example, a high-resolution image can have a large file size, making it unsuitable for a good user experience. Reducing image dimensions can help in optimizing images. I will share a story that prompted this talk about the importance of image dimensions. When building a mobile app with heavy image content, we encountered crashes after a few pages.

And the other thing I want to talk about is the image dimensions. So, specifically, the width and the height of the image, which also matters. And I've added a question mark here that's because you might not realize just how much it matters.

When I was talking about optimizing images yesterday with a couple of people, a lot of people wondered how come we're still solving an image optimizing problem? People were trying to optimize images ten years ago. When I was talking about the topic of my talk, we kind of came to the conclusion that people have been doing this similar kind of thing for years and years and years. But the problem is that as technology advances, the problem we are solving keeps getting harder.

So to give you an example, this is an image that my friend Taz took of me a couple of weeks ago. Taz is a very good camera, top of the range. And it's great. I can zoom in, go all CSI, and figure out exactly what time it was when this image was taken. However, this kind of resolution comes with the cost of file size. So if I dig into the metadata of the file, I see that this image alone is 21 megabytes. And it's 8,000 by 5,000 pixels. So this is the source image that your photographer these days with a good camera is going to give you to use on your websites and mobile apps. And obviously you can't plop that in straight away because that is not going to give a good user experience. So if I wanted to use this on my website, I might reduce the dimensions, run it through the trustworthy Panda at TinyPNG, and I might end up with something much smaller. So this is 100 megabytes. Still not ideal, but it's usable. And I've reduced the image dimensions. And you notice that I've mentioned image dimensions several times. And you might be wondering why it's even important. And I'm going to tell you a story, and this is actually the story that prompted this talk.

And this is from a couple of years ago now, quite a few years ago, when I was building a mobile app. The mobile app was ready. It wasn't live yet, it wasn't live to users. But it was ready for content managers to add content and test things out to make sure everything was ready before releasing it. And the actual app doesn't really matter for the purposes of this story. But all you need to know is that it was very image heavy. The whole app, like every single page, had lots of really professionally shot custom images in various configurations. And what we found is that the content managers came back to us, and they kept saying that after a couple of pages, the app keeps crashing.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

A Guide to React Rendering Behavior
React Advanced Conference 2022React Advanced Conference 2022
25 min
A Guide to React Rendering Behavior
Top Content
React is a library for "rendering" UI from components, but many users find themselves confused about how React rendering actually works. What do terms like "rendering", "reconciliation", "Fibers", and "committing" actually mean? When do renders happen? How does Context affect rendering, and how do libraries like Redux cause updates? In this talk, we'll clear up the confusion and provide a solid foundation for understanding when, why, and how React renders. We'll look at: - What "rendering" actually is - How React queues renders and the standard rendering behavior - How keys and component types are used in rendering - Techniques for optimizing render performance - How context usage affects rendering behavior| - How external libraries tie into React rendering
Speeding Up Your React App With Less JavaScript
React Summit 2023React Summit 2023
32 min
Speeding Up Your React App With Less JavaScript
Top Content
Too much JavaScript is getting you down? New frameworks promising no JavaScript look interesting, but you have an existing React application to maintain. What if Qwik React is your answer for faster applications startup and better user experience? Qwik React allows you to easily turn your React application into a collection of islands, which can be SSRed and delayed hydrated, and in some instances, hydration skipped altogether. And all of this in an incremental way without a rewrite.
React Concurrency, Explained
React Summit 2023React Summit 2023
23 min
React Concurrency, Explained
Top Content
React 18! Concurrent features! You might’ve already tried the new APIs like useTransition, or you might’ve just heard of them. But do you know how React 18 achieves the performance wins it brings with itself? In this talk, let’s peek under the hood of React 18’s performance features: - How React 18 lowers the time your page stays frozen (aka TBT) - What exactly happens in the main thread when you run useTransition() - What’s the catch with the improvements (there’s no free cake!), and why Vue.js and Preact straight refused to ship anything similar
The Future of Performance Tooling
JSNation 2022JSNation 2022
21 min
The Future of Performance Tooling
Top Content
Our understanding of performance & user-experience has heavily evolved over the years. Web Developer Tooling needs to similarly evolve to make sure it is user-centric, actionable and contextual where modern experiences are concerned. In this talk, Addy will walk you through Chrome and others have been thinking about this problem and what updates they've been making to performance tools to lower the friction for building great experiences on the web.
Optimizing HTML5 Games: 10 Years of Learnings
JS GameDev Summit 2022JS GameDev Summit 2022
33 min
Optimizing HTML5 Games: 10 Years of Learnings
Top Content
The open source PlayCanvas game engine is built specifically for the browser, incorporating 10 years of learnings about optimization. In this talk, you will discover the secret sauce that enables PlayCanvas to generate games with lightning fast load times and rock solid frame rates.
When Optimizations Backfire
JSNation 2023JSNation 2023
26 min
When Optimizations Backfire
Top Content
Ever loaded a font from the Google Fonts CDN? Or added the loading=lazy attribute onto an image? These optimizations are recommended all over the web – but, sometimes, they make your app not faster but slower.
In this talk, Ivan will show when some common performance optimizations backfire – and what we need to do to avoid that.

Workshops on related topic

React Performance Debugging Masterclass
React Summit 2023React Summit 2023
170 min
React Performance Debugging Masterclass
Top Content
Featured WorkshopFree
Ivan Akulov
Ivan Akulov
Ivan’s first attempts at performance debugging were chaotic. He would see a slow interaction, try a random optimization, see that it didn't help, and keep trying other optimizations until he found the right one (or gave up).
Back then, Ivan didn’t know how to use performance devtools well. He would do a recording in Chrome DevTools or React Profiler, poke around it, try clicking random things, and then close it in frustration a few minutes later. Now, Ivan knows exactly where and what to look for. And in this workshop, Ivan will teach you that too.
Here’s how this is going to work. We’ll take a slow app → debug it (using tools like Chrome DevTools, React Profiler, and why-did-you-render) → pinpoint the bottleneck → and then repeat, several times more. We won’t talk about the solutions (in 90% of the cases, it’s just the ol’ regular useMemo() or memo()). But we’ll talk about everything that comes before – and learn how to analyze any React performance problem, step by step.
(Note: This workshop is best suited for engineers who are already familiar with how useMemo() and memo() work – but want to get better at using the performance tools around React. Also, we’ll be covering interaction performance, not load speed, so you won’t hear a word about Lighthouse 🤐)
Building WebApps That Light Up the Internet with QwikCity
JSNation 2023JSNation 2023
170 min
Building WebApps That Light Up the Internet with QwikCity
Featured WorkshopFree
Miško Hevery
Miško Hevery
Building instant-on web applications at scale have been elusive. Real-world sites need tracking, analytics, and complex user interfaces and interactions. We always start with the best intentions but end up with a less-than-ideal site.
QwikCity is a new meta-framework that allows you to build large-scale applications with constant startup-up performance. We will look at how to build a QwikCity application and what makes it unique. The workshop will show you how to set up a QwikCitp project. How routing works with layout. The demo application will fetch data and present it to the user in an editable form. And finally, how one can use authentication. All of the basic parts for any large-scale applications.
Along the way, we will also look at what makes Qwik unique, and how resumability enables constant startup performance no matter the application complexity.
Introducing FlashList: Let's build a performant React Native list all together
React Advanced Conference 2022React Advanced Conference 2022
81 min
Introducing FlashList: Let's build a performant React Native list all together
Top Content
WorkshopFree
David Cortés Fulla
Marek Fořt
Talha Naqvi
3 authors
In this workshop you’ll learn why we created FlashList at Shopify and how you can use it in your code today. We will show you how to take a list that is not performant in FlatList and make it performant using FlashList with minimum effort. We will use tools like Flipper, our own benchmarking code, and teach you how the FlashList API can cover more complex use cases and still keep a top-notch performance.You will know:- Quick presentation about what FlashList, why we built, etc.- Migrating from FlatList to FlashList- Teaching how to write a performant list- Utilizing the tools provided by FlashList library (mainly the useBenchmark hook)- Using the Flipper plugins (flame graph, our lists profiler, UI & JS FPS profiler, etc.)- Optimizing performance of FlashList by using more advanced props like `getType`- 5-6 sample tasks where we’ll uncover and fix issues together- Q&A with Shopify team
Next.js 13: Data Fetching Strategies
React Day Berlin 2022React Day Berlin 2022
53 min
Next.js 13: Data Fetching Strategies
Top Content
WorkshopFree
Alice De Mauro
Alice De Mauro
- Introduction- Prerequisites for the workshop- Fetching strategies: fundamentals- Fetching strategies – hands-on: fetch API, cache (static VS dynamic), revalidate, suspense (parallel data fetching)- Test your build and serve it on Vercel- Future: Server components VS Client components- Workshop easter egg (unrelated to the topic, calling out accessibility)- Wrapping up
Detox 101: How to write stable end-to-end tests for your React Native application
React Summit 2022React Summit 2022
117 min
Detox 101: How to write stable end-to-end tests for your React Native application
Top Content
WorkshopFree
Yevheniia Hlovatska
Yevheniia Hlovatska
Compared to unit testing, end-to-end testing aims to interact with your application just like a real user. And as we all know it can be pretty challenging. Especially when we talk about Mobile applications.
Tests rely on many conditions and are considered to be slow and flaky. On the other hand - end-to-end tests can give the greatest confidence that your app is working. And if done right - can become an amazing tool for boosting developer velocity.
Detox is a gray-box end-to-end testing framework for mobile apps. Developed by Wix to solve the problem of slowness and flakiness and used by React Native itself as its E2E testing tool.
Join me on this workshop to learn how to make your mobile end-to-end tests with Detox rock.
Prerequisites- iOS/Android: MacOS Catalina or newer- Android only: Linux- Install before the workshop
How to Build an Interactive “Wheel of Fortune” Animation with React Native
React Summit Remote Edition 2021React Summit Remote Edition 2021
60 min
How to Build an Interactive “Wheel of Fortune” Animation with React Native
Top Content
Workshop
Oli Bates
Oli Bates
- Intro - Cleo & our mission- What we want to build, how it fits into our product & purpose, run through designs- Getting started with environment set up & “hello world”- Intro to React Native Animation- Step 1: Spinning the wheel on a button press- Step 2: Dragging the wheel to give it velocity- Step 3: Adding friction to the wheel to slow it down- Step 4 (stretch): Adding haptics for an immersive feel