Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
L

lazyframe

> 编程语言
Open source

Dependency-free library for lazyloading iframes

384 stars0 likes2 views
WebsiteGitHub

About

Dependency-free library for lazyloading iframes

Lazyframe

Dependency-free library for lazyloading iframes. Demo

Why?

Because embedded content takes time to load.

  • Youtube – 11 requests ≈ 580kb
  • Google maps – 52 requests ≈ 580kb
  • Vimeo – 8 requests ≈ 145kb

Lazyframe creates a responsive placeholder for embedded content and requests it when the user interacts with it. This decreases the page load and idle time.

Lazyframe comes with brand-like themes for Youtube and Vimeo.

  1. Install
  2. Import
  3. Initialize
  4. Options

Install

NPM

bash
$ npm install lazyframe --save

Bower

bash
$ bower install lazyframe

Import

JavaScript ES6 imports

javascript
import lazyframe from "lazyframe";

Include JavaScript in html

xml

Sass import

sass
@import 'src/scss/lazyframe'

Include css in html

xml

Initialize

javascript
// Passing a selector
lazyframe(".lazyframe");

// Passing a nodelist
let elements = document.querySelectorAll(".lazyframe");
lazyframe(elements);

// Passing a jQuery object
let elements = $(".lazyframe");
lazyframe(elements);

Options

You can pass general options to lazyframe on initialization. Element-specific options (most options) are set on data attributes on the element itself.

General options and corresponding defaults

javascript
lazyframe(elements, {
  debounce: 250,
  lazyload: true,
  autoplay: true,

  // Callbacks
  onLoad: (lazyframe) => console.log(lazyframe),
  onAppend: (iframe) => console.log(iframe),
  onThumbnailLoad: (img) => console.log(img),
});

debounce

Value (in milliseconds) for when the update function should run after the user has scrolled. More here

lazyload

Set this to false if you want all API calls and local images to be loaded on page load (instead of when the element is in view).

autoplay

Set this to false to remove autoplay from the allow attribute on the iframe tag i.e if set this to false if you want don't want your Youtube video to automatically start playing once the user clicks on the play icon.

onLoad

Callback function for when a element is initialized.

onAppend

Callback function for when the iframe is appended to DOM.

onThumbnailLoad

Callback function with the thumbnail URL

Element-specific options

xml

data-vendor

Attribute for theming lazyframe. Currently supported values are youtube, youtube_nocookie and vimeo.

data-title

Attribute for custom title. Leave empty to get value from noembed.com.

data-thumbnail

Attribute for custom thumbnail. Leave empty to get value from noembed.com.

data-src

The source of what you want to lazyload.

data-ratio

The ratio of the lazyframe. Possible values: 16:9, 4:3, 1:1

data-initinview

Set this to true if you want the resource to execute (for example video to play) when the element is in view.

License

MIT. © 2016 Viktor Bergehall

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScriptes6iframejavascriptlazyloading

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言