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.

This talk has been presented at React Summit 2023, check out the latest edition of this React Conference.

Watch video on a separate page

FAQ

Kati Cremmann is the director of engineering for mobile at Promotable, a JavaScript consultancy specializing in React and React Native.

The main topic of Kati Cremmann's speech is optimizing images for mobile and web.

The two ways to optimize images mentioned by Kati Cremmann are optimizing the content of the image (e.g., cropping) and optimizing the file size.

An aspect ratio is a ratio between the width and height of an image, which helps in communicating the required image dimensions to designers and photographers.

Image file size is important because large files can slow down the loading time of web and mobile applications, leading to a poor user experience.

Kati Cremmann faced a problem where the mobile app kept crashing after navigating a few pages because the images were too large and consumed too much memory.

Pixel density affects image quality because it determines how many pixels make up a display point. Higher pixel density means more pixels per display point, which can make images look sharper.

The recommended solution is to generate multiple versions of the image at different sizes during build time or use a content delivery network (CDN) to serve the appropriate image size on the fly.

Kati Cremmann recommends using tools like Cloudinary for image optimization, as they can automatically serve the best image format for different platforms.

Using a single large image for all devices is not ideal because it can burden lower-end devices with the task of resizing the image, leading to slower performance and potential crashes.

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
This transcription provides a brief guide to React rendering behavior. It explains the process of rendering, comparing new and old elements, and the importance of pure rendering without side effects. It also covers topics such as batching and double rendering, optimizing rendering and using context and Redux in React. Overall, it offers valuable insights for developers looking to understand and optimize 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
Watch video: Speeding Up Your React App With Less JavaScript
Mishko, the creator of Angular and AngularJS, discusses the challenges of website performance and JavaScript hydration. He explains the differences between client-side and server-side rendering and introduces Quik as a solution for efficient component hydration. Mishko demonstrates examples of state management and intercommunication using Quik. He highlights the performance benefits of using Quik with React and emphasizes the importance of reducing JavaScript size for better performance. Finally, he mentions the use of QUIC in both MPA and SPA applications for improved startup performance.
React Concurrency, Explained
React Summit 2023React Summit 2023
23 min
React Concurrency, Explained
Top Content
Watch video: React Concurrency, Explained
React 18's concurrent rendering, specifically the useTransition hook, optimizes app performance by allowing non-urgent updates to be processed without freezing the UI. However, there are drawbacks such as longer processing time for non-urgent updates and increased CPU usage. The useTransition hook works similarly to throttling or bouncing, making it useful for addressing performance issues caused by multiple small components. Libraries like React Query may require the use of alternative APIs to handle urgent and non-urgent updates effectively.
The Future of Performance Tooling
JSNation 2022JSNation 2022
21 min
The Future of Performance Tooling
Top Content
Today's Talk discusses the future of performance tooling, focusing on user-centric, actionable, and contextual approaches. The introduction highlights Adi Osmani's expertise in performance tools and his passion for DevTools features. The Talk explores the integration of user flows into DevTools and Lighthouse, enabling performance measurement and optimization. It also showcases the import/export feature for user flows and the collaboration potential with Lighthouse. The Talk further delves into the use of flows with other tools like web page test and Cypress, offering cross-browser testing capabilities. The actionable aspect emphasizes the importance of metrics like Interaction to Next Paint and Total Blocking Time, as well as the improvements in Lighthouse and performance debugging tools. Lastly, the Talk emphasizes the iterative nature of performance improvement and the user-centric, actionable, and contextual future of performance tooling.
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
PlayCanvas is an open-source game engine used by game developers worldwide. Optimization is crucial for HTML5 games, focusing on load times and frame rate. Texture and mesh optimization can significantly reduce download sizes. GLTF and GLB formats offer smaller file sizes and faster parsing times. Compressing game resources and using efficient file formats can improve load times. Framerate optimization and resolution scaling are important for better performance. Managing draw calls and using batching techniques can optimize performance. Browser DevTools, such as Chrome and Firefox, are useful for debugging and profiling. Detecting device performance and optimizing based on specific devices can improve game performance. Apple is making progress with WebGPU implementation. HTML5 games can be shipped to the App Store using Cordova.
Power Fixing React Performance Woes
React Advanced Conference 2023React Advanced Conference 2023
22 min
Power Fixing React Performance Woes
Top Content
Watch video: Power Fixing React Performance Woes
This Talk discusses various strategies to improve React performance, including lazy loading iframes, analyzing and optimizing bundles, fixing barrel exports and tree shaking, removing dead code, and caching expensive computations. The speaker shares their experience in identifying and addressing performance issues in a real-world application. They also highlight the importance of regularly auditing webpack and bundle analyzers, using tools like Knip to find unused code, and contributing improvements to open source libraries.

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