White background when image loads

Hi. This is my site in Next.js. When the page reloads, a white background is displayed behind the image of the hero section, especially when you visit another page from the navbar like About or Solutions Can we avoid it or reduce this effect? https://visible-paths-six.vercel.app/
VisiblePaths | Welcome
VisiblePaths is a platform for your cars
10 Replies
Chris Bolson
Chris Bolson3mo ago
I would initally recommend a couple of things. 1. Preload the first image using the <link rel="preload"> tag. 2. Remove the loading="lazy" from the first image. This is potentially slowing down it's load time as the browser is waiting to load it.
ἔρως
ἔρως3mo ago
this is known as a fouc - flash of unstyled content besides what chris said, i would add JUUUUUUUUUST the bare minimum css to show the background image and i would go even further: reduce the image to about 32 width, and then blur the living shit out of that then, convert the result to a base64 data uri and use that image as a shitty placeholder, until the big one loads this way, you no longer have a flash of white
Chris Bolson
Chris Bolson3mo ago
You could also add the attribute fetchpriority="high" to the first image to encourage the browser to load it sooner. (this might not work on all browsers).
ἔρως
ἔρως3mo ago
yes, that could work but it depends if the cache is set properly too
Chris Bolson
Chris Bolson3mo ago
that is another thing - the cache As the image URLs have paramters they most likely won't be stored in the cache
ἔρως
ἔρως3mo ago
if it is set to revalidate, then it will contact the server first, and will always flash white which is why i gave the suggestion of using a base64 shitty version of the big image
ABUL KALAM
ABUL KALAMOP3mo ago
Okay. Thank you guys, a lot. That was a great idea.
ἔρως
ἔρως3mo ago
did it worked?
clevermissfox
clevermissfox3mo ago
How do you use it as a placeholder ? Do you put it underneath the other image tag ?
ἔρως
ἔρως3mo ago
either as a background or as the src that loads and that then you swap for the big image both should work fine if it is a base64 data uri, then it should load nearly instantly, which makes it great for this
Want results from more Discord servers?
Add your server