Switch to background-image for placeholder image #16
Closed
felixranesberger
started this conversation in
Ideas
Replies: 2 comments 1 reply
-
A solution could look like this: // Generate the blurry placeholder from a Blurhash or ThumbHash string if applicable
if (__ENABLE_HASH_DECODING__ && hash) {
const placeholder = createPlaceholderFromHash({
image,
hash: typeof hash === 'string' ? hash : undefined,
hashType,
size: placeholderSize,
})
if (placeholder) {
image.style.backgroundImage = `url('${placeholder}')`;
image.style.backgroundSize = 'cover';
image.style.backgroundPosition = 'center';
}
...
} |
Beta Was this translation helpful? Give feedback.
1 reply
-
Thanks for the input! Using Regarding the CLS, have you read the unlazy docs on |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Johann, when using a ThumbHash that doesn't match the exact width and height of the output image,
a CLS does occur, because the decoded URI has different dimensions.
I'm facing this exact issue, because of performance reasons, I can't generate a new ThumbHash for each new image crop variant.
Would it be possible, to switch from setting the data-uri on the
src
attribute, to using abackground-image
solution?A solution could look something like this:
(
src="#"
causes W3C-Validator to succeed and avoids unnecessary 1px placeholder image)If this approach is fine with you, I would love to provide a pull request for the feature.
Beta Was this translation helpful? Give feedback.
All reactions