All Projects â†’ johannschopplich â†’ loadeer

johannschopplich / loadeer

Licence: MIT license
đŸĻŒ Tiny, performant, SEO-friendly lazy loading library

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to loadeer

Responsively Lazy
Lazy load responsive images
Stars: ✭ 1,080 (+3500%)
Mutual labels:  lazyload, lazy-loading
React Progressive Loader
Utility to load images and React components progressively, and get code splitting for free
Stars: ✭ 224 (+646.67%)
Mutual labels:  lazyload, lazy-loading
Yall.js
A fast, flexible, and small SEO-friendly lazy loader.
Stars: ✭ 1,163 (+3776.67%)
Mutual labels:  lazyload, lazy-loading
Nuxt Lazysizes
Lazysizes module for Nuxt.js
Stars: ✭ 25 (-16.67%)
Mutual labels:  lazyload, lazy-loading
Universal
Seed project for Angular Universal apps featuring Server-Side Rendering (SSR), Webpack, CLI scaffolding, dev/prod modes, AoT compilation, HMR, SCSS compilation, lazy loading, config, cache, i18n, SEO, and TSLint/codelyzer
Stars: ✭ 669 (+2130%)
Mutual labels:  seo, lazy-loading
Lozad.js
đŸ”Ĩ Highly performant, light ~1kb and configurable lazy loader in pure JS with no dependencies for responsive images, iframes and more
Stars: ✭ 6,932 (+23006.67%)
Mutual labels:  lazyload, lazy-loading
Ng In Viewport
Allows us to check if an element is within the browsers visual viewport
Stars: ✭ 178 (+493.33%)
Mutual labels:  lazyload, lazy-loading
Accessible Image Lazy Load
😴 gandul! accessible lazy loading images
Stars: ✭ 281 (+836.67%)
Mutual labels:  lazyload, lazy-loading
React Cool Img
😎 🏞 A React <Img /> component let you handle image UX and performance as a Pro!
Stars: ✭ 356 (+1086.67%)
Mutual labels:  seo, lazy-loading
angular-app
Angular 14 ,Bootstrap 5, Node.js, Express.js, ESLint, CRUD, PWA, SSR, SEO, Universal, Lazy Loading
Stars: ✭ 389 (+1196.67%)
Mutual labels:  seo, lazy-loading
lazy-load-images.js
Progressive & lazy loading images.
Stars: ✭ 17 (-43.33%)
Mutual labels:  lazyload, lazy-loading
rocket-lazy-load
Standalone LazyLoad plugin for WordPress (based on WP Rocket)
Stars: ✭ 25 (-16.67%)
Mutual labels:  lazyload, lazy-loading
React Lazy Load Image Component
React Component to lazy load images and components using a HOC to track window scroll position.
Stars: ✭ 755 (+2416.67%)
Mutual labels:  lazyload, lazy-loading
Jquery.lazy
A lightweight, fast, feature-rich, powerful and highly configurable delayed content, image and background lazy loading plugin for jQuery & Zepto.
Stars: ✭ 965 (+3116.67%)
Mutual labels:  lazyload, lazy-loading
Vanilla Lazyload
LazyLoad is a lightweight, flexible script that speeds up your website by deferring the loading of your below-the-fold images, backgrounds, videos, iframes and scripts to when they will enter the viewport. Written in plain "vanilla" JavaScript, it leverages IntersectionObserver, supports responsive images and enables native lazy loading.
Stars: ✭ 6,596 (+21886.67%)
Mutual labels:  lazyload, lazy-loading
React Lazy
Universal lazy loader components using IntersectionObserver for React
Stars: ✭ 118 (+293.33%)
Mutual labels:  lazyload, lazy-loading
jekyll-loading-lazy
🧙đŸŊ‍♀ī¸ Automatically adds loading="lazy" to <img> and <iframe> tags. Load images on your sites lazily without JavaScript.
Stars: ✭ 41 (+36.67%)
Mutual labels:  lazyload, lazy-loading
magento2-catalog-lazy-load
Improve the load time of your Magento 2 categories pages by loading your images on demand with our Lazy Load Extension
Stars: ✭ 56 (+86.67%)
Mutual labels:  lazyload, lazy-loading
example-app
Example app showcasing fulls1z3's Angular libraries
Stars: ✭ 27 (-10%)
Mutual labels:  seo, lazy-loading
Angular11 App
Angular 11 ,Bootstrap 5, Node.js, Express.js, CRUD REST API, PWA, SSR, SEO, Angular Universal, Lazy Loading, PostgreSQL, MYSQL
Stars: ✭ 233 (+676.67%)
Mutual labels:  seo, lazy-loading

Logo of Loadeer.js

Loadeer.js

Tiny, performant, SEO-friendly lazy loading library


Loadeer.js

Performant, SEO-friendly and configurable library to lazily load images using the IntersectionObserver API.

If you have used Lozad.js, then you already know how to use Loadeer.js. This library is basically an overhauled and opiniated version of Lozad.js, which includes sizes support, makes usage of data attributes instead of classes and is written in TypeScript.

Loadeer.js is intended to be used with images.

Key Features

  • 🍃 Zero dependencies: 0.9kB minified & gzipped
  • 🎀 Native: Uses native loading="lazy" if supported and enabled
  • 🏎 Auto initialize: with the init script attribute
  • đŸĒ„ Sizing: Automatically calculates the sizes attribute
  • 🔧 Customizable: Use data attributes for image sources
  • 🎟 <picture>: Supports multiple image formats
  • 🔍 SEO-friendly: Detects e.g. Google Bot and preloads all images

Installation

Loadeer.js can be used without a build step. Simply load it from a CDN:

<script src="https://unpkg.com/loadeer" defer init></script>

<!-- Anywhere on the page -->
<img
  data-lazyload
  data-src="/foo.png"
  data-srcset="/foo.png 1024w, /foo-2x.png 2048w"
/>

<!-- Or use the picture tag instead -->
<picture>
  <source data-lazyload data-srcset="/bar.jpg" media="(min-width: 800px)">
</picture>
  • The defer attribute makes the script execute after HTML content is parsed.
  • The init attribute tells Loadeer.js to automatically initialize and watch all elements that have a data-lazyload attribute.

Manual Initialization

If you don't want the auto initialize, remove the init attribute and move the scripts to end of <body>:

<script src="https://unpkg.com/loadeer"></script>
<script>
  const loadeer = new Loadeer()
  loadeer.observe()
</script>

Or, use the ES module build by installing the loadeer npm package:

import Loadeer from 'loadeer'

const loadeer = new Loadeer()
loadeer.observe()

Production CDN URLs

The short CDN URLs are meant for prototyping. For production usage, use a fully resolved CDN URL to avoid resolving and redirect cost:

Usage

Basic

Add the data-lazyload attribute to an element of your choice which you seek to lazily load. Set an data-src or data-srcset attribute as well.

<!-- You can use the img tag -->
<img data-lazyload data-src="image.png" />

<!-- â€Ļ or the picture element -->
<picture>
  <source data-lazyload data-srcset="/foo.jpg" media="(min-width: 800px)">
</picture>

Although Loadeer.js' default selector is data-lazyload, you may configure it to a selector of your choice. See the libraries options for more information.

Finally, instantiate Loadeer.js as follows:

const instance = new Loadeer()
// Lazily loads all `data-lazyload` images
instance.observe()

Native Lazy Loading

ℹī¸ Use with caution. Especially if placeholder images are used, the native lazy loading attribute interferes, since all data-src attributes will be converted to src once Loadeer.js runs. All placeholder images will be overwritten and if the images are loaded slower than the user scrolls, blank spaces will occur. Thus, Loadeer.js doesn't enable native lazy loading by default.

Browser support for loading="lazy" is decent. At the time writing, only Safari lacks support. If the option useNativeLoading is set to true and Loadeer.js detects the browser supports lazy loading, the loading attribute will be set to lazy and all data-src attributes changed to src. No intersection observer will be initialized.

Use the default selector:

<img data-lazyload data-src="image.png" />

Or use the future-proof loading attribute as selector:

<img loading="lazy" data-src="image.png" />

Finally, change the default selector parameter for the latter case:

const instance = new Loadeer('img[loading="lazy"]')
instance.observe()

Auto Calculation of the sizes Attribute

Loadeer.js supports setting the sizes attribute automatically, corresponding to the current size of your image – just set the value of data-sizes to auto.

The automatic sizes calculation uses the display width of the image.

<img
  data-lazyload
  data-srcset="image-480w.jpg 480w, image-800w.jpg 800w"
  data-sizes="auto"
/>

Custom Selector

You may pass an element or array of elements to the constructor as well:

const root = document.querySelector('#app')
const instance = new Loadeer(root)
instance.observe()

See the API for all available options.

Trigger Loading of Images Manually

If you want to load the images before they appear, use the triggerLoad method.

const instance = new Loadeer()
instance.observe()

const coolImage = document.querySelector('.image-to-load-first')
// Trigger the load before the image appears in the viewport
observer.triggerLoad(coolImage)

Custom Options

Pass a onLoaded function to either manipulate the loaded element or do anything else with it.

const onLoaded = (element) => {
  console.log('Lazily loaded element:', element)
}

const instance = new Loadeer('[data-lazyload]', {
  root: document.querySelector('#app'),
  rootMargin: '10px 0px',
  threshold: 0.1,
  onLoaded,
})

instance.observe()

Both the rootMargin and thresholds options are passed to directly to the IntersectionObserver and thus infer their respective types.

API

new Loadeer(selector, options: LoadeerOptions = {})

Selector

Defaults to [data-lazyload]. Allowed types are:

  • string
  • HTMLImageElement
  • Array<HTMLImageElement>
  • NodeListOf<HTMLImageElement>

LoadeerOptions

Note: Every property is optional to pass to the Loadeer.js constructor.

Option Default Type Description
root document Element, Document, null, undefined The container within elements will be lazily loaded.
rootMargin 0px string, undefined See IntersectionObserver rootMargin parameter.
threshold 0 number, number[], undefined See IntersectionObserver threshold parameter.
onLoaded undefined (element: HTMLElement) => void, undefined Custom function to run after each image is loaded.
useNativeLoading false boolean, undefined Indicates if the native loading="lazy" attribute should be used (if supported by the browser).

SEO

Loadeer.js does not hide elements from Google. The library detects whether the user agent is probably a bot or crawler and will load all images.

Credits

License

MIT License Š 2021-2022 Johann Schopplich

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].