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.

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

FAQ

SRC set attributes enable web developers to specify a list of images and different sizes for those images. This allows browsers to select and display the most appropriate image based on the device's screen size and resolution, enhancing the responsiveness and performance of websites.

The picture element is used less frequently than the SRC set because it involves more complexity and is generally used for more specific scenarios where different image sources are needed for different displays or orientations, not just different sizes.

Factors to consider when deciding on image storage include the number of images, ease of support, total number of transformation operations, frequency of design changes, and whether you are using an image CDN. These elements affect accessibility, performance, and maintenance of image data.

Main image transformation operations include cropping, resizing, filtering, optimization, and transformation for security. Additional operations might involve blurring, text addition, flipping, adding outlines, and shadows, among other special effects, enhancing the visual appeal and functionality of images.

Modern image formats like WWF and WP are recommended due to their efficient compression and quality benefits over older formats like JPG and PNG. These newer formats help in improving the loading times and visual quality on modern devices.

Web developers should provide multiple image sizes to accommodate various screen sizes and resolutions. The exact number of sizes depends on the design specifics and the range of devices the website targets. This ensures optimal image display and performance across all devices.

Options for integrating responsive images into an existing app include preparing various versions of the same image to be stored on a server or CDN, using a proxy server for on-the-fly optimization and transformation, or utilizing an ImageCDN service like Cloudinary or Amazon.

Sergey Bocharov
Sergey Bocharov
7 min
05 Jun, 2023

Comments

Sign in or register to post your comment.

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.

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

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.
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
React Performance Debugging
React Advanced Conference 2023React Advanced Conference 2023
148 min
React Performance Debugging
Workshop
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 🤐)
High-performance Next.js
React Summit 2022React Summit 2022
50 min
High-performance Next.js
Workshop
Michele Riva
Michele Riva
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.
Maximize App Performance by Optimizing Web Fonts
Vue.js London 2023Vue.js London 2023
49 min
Maximize App Performance by Optimizing Web Fonts
WorkshopFree
Lazar Nikolov
Lazar Nikolov
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