johannschopplich/unlazy
关于
🪧 使用 BlurHash 和 ThumbHash 占位图实现原生图片懒加载,支持原生 JS、Vue、React、Svelte、Solid 和 Nuxt
网站与应用开发可以做什么
- 🎀 Native: Utilizes the loading="lazy" attribute
- 🎛️ Framework-agnostic: Works with any framework or no framework at all
- 🌊 BlurHash & ThumbHash support: SSR & client-side BlurHash and ThumbHash decoding
- ⚡ Core Web Vitals-aware: Eager-priority path for above-the-fold images, dev-mode LCP warning
实测星标增长
- 24小时
- 0
- 7天
- +2
- 15天
- +2
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文unlazy
Native image lazy loading for vanilla JS, Vue, React, Svelte, Solid and Nuxt. Built around the loading="lazy" attribute, with BlurHash / ThumbHash placeholders, a dedicated above-the-fold priority path, and a dev-mode LCP warning so you never ship a lazy-loaded hero image by accident.
Features
- 🎀 Native: Utilizes the
loading="lazy"attribute - 🎛️ Framework-agnostic: Works with any framework or no framework at all
- 🌊 BlurHash & ThumbHash support: SSR & client-side BlurHash and ThumbHash decoding
- ⚡ Core Web Vitals-aware: Eager-priority path for above-the-fold images, dev-mode LCP warning
- 🪄 Sizing: Automatically calculates the
sizesattribute - 🔍 SEO-friendly: Detects search engine bots and preloads all images
- 🎟
<picture>: Art direction and format selection with multiple sources - 🏎 Auto-initialize: Usable without a build step
Installation
# pnpm
pnpm add unlazy
# npm
npm i unlazy
For a framework, install its integration instead:
- Vue:
@unlazy/vue - Nuxt:
@unlazy/nuxt - React:
@unlazy/react - Solid:
@unlazy/solid - Svelte:
@unlazy/svelte
Basic Usage
Mark an image with loading="lazy" and put its source into data-src or data-srcset:
<img loading="lazy" data-src="image.jpg" width="640" height="360" alt="Descriptive text" />
Then import the lazyLoad function and call it without arguments to process all matching images:
import { lazyLoad } from 'unlazy'
// Processes every image with a `data-src` or `data-srcset`
lazyLoad()
For above-the-fold images (your hero / LCP image), use loading="eager". unlazy swaps the real source immediately and applies fetchpriority="high" for you:
<img loading="eager" data-src="hero.jpg" width="1600" height="900" alt="Sunset" />
To target specific images, pass a CSS selector, a DOM element, a list of DOM elements, or an array of DOM elements to lazyLoad.
💻 Development
- Clone this repository
- Enable Corepack using
corepack enable - Install dependencies using
pnpm install - Run
pnpm run dev:prepare - Start a development server using
pnpm run devinside one of the framework packages, such aspackages/vue
License
MIT License © 2023-PRESENT Johann Schopplich
探索相关项目
加载中…
