Responsive Images for Your Website

Rate this content
Bookmark

Why bother to optimize images? Images often account for most of the downloaded bytes on a web page. As a result, optimizing images can frequently yield of the performance improvements for your website.

7 min
05 Jun, 2023

Video Summary and Transcription

The Talk discusses various aspects of serving images on websites, including where to store images, image transformation options, and image formats. It also explores different approaches for handling image versions and sizes, such as preparing them in advance or using a proxy server. The speaker highlights the importance of optimizing images for performance and mentions the progress made in adopting new image formats. Overall, the Talk provides insights into best practices for managing and serving responsive dynamic images.

Available in Español

1. Introduction to Responsive Dynamic Images

Short description:

Hi, everyone, my name is Sergei Bucharov, and I'm super excited today to talk about responsive dynamic images at the JS Nation conference. I am Fullstack's Sber, and today I'm going to talk about different ways to serve images on your site. I recently read a report on the state of the web and realized how much more needs to be done on this issue. Let's try to answer these questions. First question. Where do I keep my images, locally or remotely? What transformation operations can we perform? The second question is, what format should images be kept in? According to HTTP archive, the leading positions are occupied by JIF, JPG, and PNG, which can help, but upset me.

Hi, everyone, my name is Sergei Bucharov, and I'm super excited today to talk about responsive dynamic images at the JS Nation conference. I am Fullstack's Sber, and today I'm going to talk about different ways to serve images on your site. I recently read a report on the state of the web and realized how much more needs to be done on this issue.

One-third of pages use the SRC set, but two-thirds don't. First, in 2014, the SRC set attributes, sizes attribute, and the picture element have allowed office to mock up adaptable resources for almost a decade now. The picture element is used far less than the SRC set. By now, you probably know that implementing image upload is not an easy issue. So many questions instantly arise, including some big ones like 1. Where do I keep my images, locally or remotely? 2. What format should images be kept in? 3. How do I handle image transformations, and where do I keep various versions of the same image? 4. How many image sizes to provide to web browsers? 5. How do I plug everything into my existing app? Certainly, there are a plethora of ready-made solutions available, so you can pick one, but more about them later. Let's try to answer these questions.

First question. Where do I keep my images, locally or remotely? It depends on many factors, both technical and business, for example, 1. the number of images 2. ease of support 3. the total number of transformations operations 4. the picture plan, if you are using IMAGE CDM 5. the frequency of design changes 6. and many others What transformation operations can we perform? I usually divide these operations into two groups, main and additional. The main group includes cropping, resizing, filtering, optimization, and transformation. And, of course, you need to remember about protection. The additional group includes blurring, text addition, flipping, outlines, and shadows, and many other special effects. Therefore, you should think about your purposes and choose the type of storage. If you need only cropping and resizing, you can do it on your server. I will show you how to do it later.

The second question is, what format should images be kept in? According to HTTP archive, the leading positions are occupied by JIF, JPG, and PNG, which can help, but upset me. At 0.22% a WWF slice of 3Py is so small, it is not even labeled on the chart.

2. Handling Image Transformations and Upload Options

Short description:

And while 0.22% may not sound like a lot, compared to last year, it represents quite a bit of progress. Slowly, the old formats are making way for the new ones, as they should. The new formats outperform the old ones by a significant margin. This chart shows bits per pixel by format. The third question is, how do I handle image transformations, and where do I keep various versions of the same image? There are a lot of tools for image optimizations and transformations. The fourth question is how many image sizes to provide to web browsers? This is an interesting question and it all depends on your design. The last question is how to upload everything into my existing app? Option 1 is to prepare various versions of the same image in advance and keep them on your server. Option 2 is the same, but you can keep images on your regular CDN. Option 3 is to use a proxy server for optimization and transformation of your images. If you're comfortable with Nginx and Docker, for example, you can set up a proxy server on a remote server right away. There are a lot of different open-source projects for this purpose. I hope you have a great time at the JS Nation conference. Thanks for your time.

And while 0.22% may not sound like a lot, compared to last year, it represents quite a bit of progress. Slowly, the old formats are making way for the new ones, as they should. The new formats outperform the old ones by a significant margin. You will get a sense of that shortly.

This chart shows bits per pixel by format. As you can see, a WWF is more compressed than a WP or JPG. A WWF is a very young format, whose encoders have been quickly iterating. Answering the questions, what format should images be kept in, increased the use of modern formats such as WWF and WP, and of course JPG, where without it, reduced the use of formats like JF and PNG.

The third question is, how do I handle image transformations, and where do I keep various versions of the same image? There are a lot of tools for image optimizations and transformations. Here are some of them. This is an example of an image tag with src and sizes attributes, the familiar way to specify the location of your image. Browsers that do not support src set and sizes will fall back to src. With sizes, you specify the size of the image, and in which situation it must be displayed. This is done by a combination of a media query and the width of an image. With src set, you specify a list of images and different sizes. Another perfectly legit goal with responsive images is not just to show different sizes of the same image, but to show different images. The picture tag has the same logic, but it has a source tag.

The fourth question is how many image sizes to provide to web browsers? This is an interesting question and it all depends on your design. For example, so many images are given on the monger site. A lot, isn't it? The last question is how to upload everything into my existing app? Option 1 is to prepare various versions of the same image in advance and keep them on your server. It's a good option if you don't have thousands of images and the design doesn't change very often. Option 2 is the same, but you can keep images on your regular CDN. Option 3 is to use a proxy server for optimization and transformation of your images. If you're comfortable with Nginx and Docker, for example, you can set up a proxy server on a remote server right away. There are a lot of different open-source projects for this purpose. For example, Fumba, ImageProxy, PicFit and others. You can also write your image optimizer, for example, I've wrote on Nginx, you can view it on GitHub. The advantage is that you can create your URL structure and use only the operation you need. And of course, if Option 3 is not your cup of tea, you can use ImageCDN. For example, Codinary, Amazon, Netlify, nginx, ng-optim, Filestack, Cloudflare and many others.

I hope you have a great time at the JS Nation conference. Thanks for your time.

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

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
React Summit 2023React Summit 2023
32 min
Speeding Up Your React App With Less JavaScript
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 Summit 2023React Summit 2023
23 min
React Concurrency, Explained
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
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.

Workshops on related topic

React Summit 2023React Summit 2023
170 min
React Performance Debugging Masterclass
Featured WorkshopFree
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 🤐)
JSNation 2023JSNation 2023
170 min
Building WebApps That Light Up the Internet with QwikCity
Featured WorkshopFree
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.
React Day Berlin 2022React Day Berlin 2022
53 min
Next.js 13: Data Fetching Strategies
Top Content
WorkshopFree
- 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
React Advanced Conference 2023React Advanced Conference 2023
148 min
React Performance Debugging
Workshop
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 🤐)
Vue.js London 2023Vue.js London 2023
49 min
Maximize App Performance by Optimizing Web Fonts
WorkshopFree
You've just landed on a web page and you try to click a certain element, but just before you do, an ad loads on top of it and you end up clicking that thing instead.
That…that’s a layout shift. Everyone, developers and users alike, know that layout shifts are bad. And the later they happen, the more disruptive they are to users. In this workshop we're going to look into how web fonts cause layout shifts and explore a few strategies of loading web fonts without causing big layout shifts.
Table of Contents:What’s CLS and how it’s calculated?How fonts can cause CLS?Font loading strategies for minimizing CLSRecap and conclusion
React Summit 2022React Summit 2022
50 min
High-performance Next.js
Workshop
Next.js is a compelling framework that makes many tasks effortless by providing many out-of-the-box solutions. But as soon as our app needs to scale, it is essential to maintain high performance without compromising maintenance and server costs. In this workshop, we will see how to analyze Next.js performances, resources usage, how to scale it, and how to make the right decisions while writing the application architecture.