question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request to add [Optimized Image/Picture] component

See original GitHub issue

Is your feature request related to a problem? Please describe.

Images are the heaviest part of a website. Lazyloading is rather hard to implement and the picture/srcset syntax is all over the place and confusing for new devs. Webp is an amazing solution for this but its barely used because it’s not yet stable in every browser.

Taking care of this issue would greatly improve web accessibility for people on slow networks.

Describe the solution you’d like

An improvement to the Image component that would address all of these issues, similar to gatsby-images. Users would still need to convert and provide the images themselves but

  • lazyloading
  • webp fallbacks
  • responsive sizes are made easy.

A nice and flexible api could look like this:

<Image
	loading='lazy' // default behavior
    placeholder='img-xxs.jpg' // blured version of this is gonna be shown while the image loads
	src='img-md.jpg' // the default source and fallback
    sizes={['/img-sm.jpg', '/img-md.jpg','/img-lg.jpg']} // responsive array like styled-system that can take multiple sources
	webp={['/img-sm.webp', '/img-md.webp','/img-lg.webp']}
/>

Most keys are optional so sth like this is possible

<Image src='img-md.jpg' webp='img-md.webp' />

This integrates well with pretty much every common image optimization service like Cloudinary that provide flexible links for every size.

Describe alternatives you’ve considered

I thought about porting gatsby-image out of gatsby but the api is very specific to their image sharp configuration.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:11
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

15reactions
grsoares21commented, Jul 16, 2021

Sad to see this has gone stale, 😕. It was exactly what I was looking for.

Anyone with plans of doing a PR for this?

11reactions
subhendukunducommented, Sep 26, 2020

I see two problems with the Image component too.

  1. If the image is too big, its shows a broken image until the whole image is loaded. So I guess the proposed isLazy or adding a loading icon would be great.
  2. fallbackSrc take a string which is great but I think we should provide an ability to add a passing custom component too. So that it’s possible to pass SVG to make it more personalized.

Is anyone working on this? Otherwise, I would like to pick it up.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Basic Features: Image Optimization - Next.js
To add an image to your application, import the next/image component: import Image from 'next/image'. Now, you can define the src for your...
Read more >
How to Easily Optimize Images for Web (without Losing Quality)
Image optimization is a process of saving and delivering images in the smallest possible file size without reducing the overall image quality.
Read more >
Picture perfect image optimization for any web framework
Generating optimized images · A /img directory with 2 images inside: 1 JPG picture of a galaxy that's 300 pixels wide, and a...
Read more >
Next.js automatic image optimization with next/image
Learn about automatic image optimization and how it can benefit developers with the native, game-changing, and powerful next/image API.
Read more >
Building an effective Image Component - Chrome Developers
An image component encapsulates performance best practices and provides an out-of-the-box solution to optimize images.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found