Skip to content

Instantly share code, notes, and snippets.

@xxiz
Last active December 26, 2022 20:09
Show Gist options
  • Save xxiz/a4d822c100481d02a6355d6c89b8fcbf to your computer and use it in GitHub Desktop.
Save xxiz/a4d822c100481d02a6355d6c89b8fcbf to your computer and use it in GitHub Desktop.
background-image image optimization
// before
<div className="relative h-48 bg-center bg-cover rounded-xl" style={{ backgroundImage: `url(${cover_image})` }}></div>
// after (relative is added to classNames)
<div className="relative h-48 bg-center bg-cover rounded-xl">
<Image
alt={title}
src={cover_image}
quality={100}
fill
sizes="100vw"
style={{
objectFit: "cover",
}}
/>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment