👀 See Sanity in action: Watch product demo now →

How to improve image loading with Gatsby and gatsby-plugin-sanity-image?

9 replies
Last updated: Nov 27, 2020
how do I achieve this same result and avoid this content jankiness (image pushing down content) in Sanity? https://css-tricks.com/do-this-to-improve-image-loading-on-your-website/
I am currently editing
Blog with Gatsby
template but so far dumbfounded on how to solve this with sanity (gatsby-image seems to do it for you). Do I modify in this file here? https://github.com/ajmalafif/afif.dev/blob/develop/web/src/lib/image-url.js
or somehow I can achieve this “lazy-loading” effect by combining both
? https://github.com/sanity-io/gatsby-source-sanity#fluid
Nov 25, 2020, 5:37 PM
it seems from observation and this is anecdotal, seems like Gatsby solution do something like this to avoid the content jump https://css-tricks.com/preventing-content-reflow-from-lazy-loaded-images/
will investigate how can I figure this out for sanity on gatstby
Nov 25, 2020, 5:45 PM
I just published gatsby-plugin-sanity-image to provide an easy way to handle this. Use the
version to avoid the CLS issue.
Nov 25, 2020, 6:12 PM
shout out to
user L
now I have a solid base to start figuring this jank-free content layout. With
Slow 3G
network on devtools I have
right away!
Nov 26, 2020, 4:55 PM
kinda looks this with
from the markup it seems like it does something differently
Nov 26, 2020, 4:57 PM
You can get those thumbnails to scale up and keep your content from jumping around by putting the image in a container sized how you want, then setting the CSS on the image to
display: block; width: 100%
. Unless you are cropping the image, the LQIP should be the same aspect ratio. If you are cropping the image, you can instead set the absolute dimensions on the img element and use
object-fit: cover
on it.
Nov 26, 2020, 5:00 PM
user L
to the rescue! thanks that’s a really good pointer
Nov 26, 2020, 5:20 PM
user L
is there a way to enable discussion tab on https://github.com/coreyward/gatsby-plugin-sanity-image/ since I encounter difficulties on resizing the
which I am not sure if it’s a bug (hence i dont think i should create an issue ticket) but I also want to ask how since I tried and failed
Nov 27, 2020, 6:14 AM
figured it out by setting the CSS for
and its all worked out now! highly recommend this plugin! Now I know how to make the site jank-free 🥳
Nov 27, 2020, 8:27 AM

Sanity.io – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Related topics

Get more help in the community Slack

TopicCategoriesFeaturedRepliesLast Updated
How to deploy Gatsby sites using official Sanity starter templates25Nov 30, 2020
How to generate RSS.xml files from Sanity posts with gatsby-plugin-feed6Jan 12, 2021
How to make Algolia work with Gatsby & Sanity8Jan 7, 2021
Set up Draft Previews with Gatsby Cloud Hosting4Aug 26, 2020
How to display Sanity images in Gatsby-powered photography sites19Jun 16, 2020
Is it possible to use gatsby-image to render images loaded in Portable Text / Rich Text?8Jan 1, 2021

Related contributions

- Made with Sanity

Complex product offering with nested product structure and tiered pricing.

Kevin Green
Go to Occo

Figma Config
- Made with Sanity

Website for Config, the global design conference by Figma.

Corey Ward
Go to Figma Config

The Agnes
- Made with Sanity

A high end rental real estate site built with Gatsby, Sanity and Shopify that pulls in listing data via API and includes a headless Shopify shop.

David Gross
Go to The Agnes