Erase CLS by automatically optimizing images.
Erase CLS by automatically optimizing images.
width and height attributes to prevent layout shifts.loading="lazy" to images.Based on the article Erase CLS by automatically optimizing images with Vite.
pnpm add -D unplugin-images-cls-optimizer
[!NOTE]
Contributions, through issues or pull requests, to extend support for other frameworks are welcome!
// vite.config.ts
import imagesClsOptimizer from 'unplugin-images-cls-optimizer/vite'
export default defineConfig({
plugins: [
imagesClsOptimizer(),
],
})
This plugin scans your .vue files for <img> tags. When it finds a local image (PNG or JPG/JPEG), it:
@unpic/pixels.<img> tag with:
width and height attributes.style attribute containing the blurhash as a background image.loading="lazy".MIT License © 2025-PRESENT Estéban Soubiran
We use cookies
We use cookies to analyze traffic and improve your experience. You can accept or reject analytics cookies.