iagobruno / lazy-fragment-element

Lazily load parts of a webpage as soon as they appear in the screen.

Home Page:https://npmjs.com/package/lazy-fragment-element

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

<lazy-fragment> element

Lazily load parts of a webpage as soon as they appear in the screen.

npm npm bundle size

Installation

CDN

Include the following <script> tag in the <head> of your document:

<script src="https://unpkg.com/lazy-fragment-element"></script>

NPM

You can also install using a package manager.

npm install lazy-fragment-element
// Or
yarn add lazy-fragment-element

And then import as a module:

import 'lazy-fragment-element'

Markup

<lazy-fragment src="/lazy-part-from-server">Loading...</lazy-fragment>

The element will be entirely replaced by the HTML fragment returned by the server as soon it appears on the screen (scrolling or showing with the css property display in a parent element).

You can also defer the loading by using the disabled attribute and removing it later.

Browser support

Browsers without native custom element support require a polyfill.

  • Chrome
  • Firefox
  • Safari
  • Microsoft Edge

About

Lazily load parts of a webpage as soon as they appear in the screen.

https://npmjs.com/package/lazy-fragment-element


Languages

Language:TypeScript 61.3%Language:HTML 36.7%Language:CSS 1.9%