Giter Club home page Giter Club logo

unlazy's Introduction

unlazy library

unlazy

npm version

Universal lazy loading library leveraging native browser APIs. It's intended to be used with the loading="lazy" attribute alongside (blurry) placeholder images and with a BlurHash or ThumbHash string.

It's the modernized and now framework-agnostic rewrite of my Loadeer.js library, which uses an Intersection Observer to detect when an image enters the viewport.

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
  • ๐Ÿช„ Sizing: Automatically calculates the sizes attribute
  • ๐Ÿ” SEO-friendly: Detects search engine bots and preloads all images
  • ๐ŸŽŸ <picture>: Supports multiple image tags
  • ๐ŸŽ Auto-initialize: Usable without a build step

Note

Although the loading="lazy" attribute is supported in all major browsers, it is only available in Safari 16.4 (released March 2023) and later versions by default. It is important to consider this limitation when using unlazy for your project, as it might impact the user experience for visitors using older Safari versions or other unsupported browsers.

Setup

๐Ÿ“– Read the documentation

# pnpm
pnpm add unlazy

# npm
npm i unlazy

Basic Usage

๐Ÿ“– Read the documentation

To apply lazy loading to all images with the loading="lazy" attribute, import the lazyLoad function and call it without any arguments:

import { lazyLoad } from 'unlazy'

// Apply lazy loading for all images by the selector `img[loading="lazy"]`
lazyLoad()

You can target specific images by passing a CSS selector, a DOM element, a list of DOM elements, or an array of DOM elements to lazy-load to lazyLoad.

๐Ÿ’ป Development

  1. Clone this repository
  2. Enable Corepack using corepack enable
  3. Install dependencies using pnpm install
  4. Run pnpm run dev:prepare
  5. Start development server using pnpm run dev inside the one of the packages directories

License

MIT License ยฉ 2023-present Johann Schopplich

unlazy's People

Contributors

johannschopplich avatar felixranesberger avatar eric-hc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.