• Stars
    star
    978
  • Rank 46,823 (Top 1.0 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lazy load images using Intersection Observer, apply progressive rendering and css animations.

v-lazy-image

npm npm Donate

A Vue.js component to lazy load an image automatically when it enters the viewport using the Intersection Observer API.

⚠️ Check the practical examples and demos if you are creating a real-world or enterprise project and see how to achieve max performance using responsive images and progressive image loading.

Usage

npm install v-lazy-image

Warning: You'll need to install the w3c Intersection Observer polyfill in case you're targeting a browser which doesn't support it.

For Vue 3, import it and use it like any other component:

<script setup>
  import VLazyImage from "v-lazy-image";
</script>

For Vue 2, import it from v-lazy-image/v2:

import VLazyImage from "v-lazy-image/v2";

export default {
  components: {
    VLazyImage
  }
};

You must pass an src property with the link of the image:

<template>
  <v-lazy-image src="http://lorempixel.com/400/200/" />
</template>

That easy, the image will be loaded as soon as it enters the viewport. See it running in this demo and you'll learn how to use Chrome DevTools to check how it's loaded.

Achieving Max Performance

Just by using v-lazy-image you'll have a performance gain, since the image will be loaded when it's going to be seen.

But you can go to the next level and squeeze your web's performance if you use the next techniques.

Responsive Images

v-lazy-image allows you to use Web Standard's: the srcset attribute on images and the <picture> tag.

"Use Responsive Images with v-lazy-image" shows you how simple it is and see it in action in a demo.

Progressive Image Loading

A technique used by platforms like Spotify, Netflix or Medium to improve Perceived Performance, thus the User Experience.

In "Achieve Max Performance loading your images with v-lazy-image" you'll see what's progressive image loading about, how to apply it in v-lazy-image using the src-placeholder attribute and a demo to see how it plays with a CSS animation.

API

Aside from the following API, you can pass any img attribute, such as alt, and they'll be added to the rendered <img> tag.

Fields marked as (*) are required.

Props

Name Type Default Description
src String (*) - Image src to lazy load when it intersects with the viewport
src-placeholder String ' ' If defined, it will be shown until the src image is loaded.
Useful for progressive image loading, see demo
srcset String - Images to be used for different resolutions
intersection-options Object () => ({}) The Intersection Observer options object.
use-picture Boolean false Wrap the img in a picture tag.

Events

Name Description
intersect Triggered when the image intersects the viewport
load Triggered when the lazy image defined in src is loaded
error Triggered when the lazy image defined in src fails to load

More Repositories

1

typescript-library-starter

Starter kit with zero-config for building a library in TypeScript, featuring RollupJS, Jest, Prettier, TSLint, Semantic Release, and more!
TypeScript
4,348
star
2

v-runtime-template

Vue component for compiling templates on the fly using a v-html like API
JavaScript
605
star
3

vue-testing-series

JavaScript
158
star
4

Vue-Typescript-Starter

TypeScript starter project based on Vue-cli webpack template
JavaScript
62
star
5

Egghead-Vuex-TypeScript

JavaScript
48
star
6

Egghead-Typescript-Vuejs-apps

JavaScript
42
star
7

vue-pwa

Vue
20
star
8

narutodose

Vue
17
star
9

vue-styleguidist-example

Example on how to use vue-styleguidist with minimal setup
Vue
14
star
10

alexjover.com

Vue
12
star
11

interviews

Code challenges for interviews I made
JavaScript
11
star
12

Faelo-food-order-app-MEAN.js-

Full-Stack food order system made in MEAN.js
JavaScript
10
star
13

storyblok-nuxt3

Vue
10
star
14

react-native-gps-logger

GPS Logger that runs in background using React Native
Java
9
star
15

links

Links and Resources to keep organized my personal interests
7
star
16

nuxt3-storyblok-ecommerce

JavaScript
6
star
17

blog

My personal blog (src)
CSS
6
star
18

Egghead-Vue-Async-Components

Example that shows how to create async components in Vue
JavaScript
5
star
19

reactive-grocery-app-slides

https://alexjoverm.github.io/reactive-grocery-app-slides/
HTML
5
star
20

javascript-algorithms-es6

A set of algorithms written in ES6+
JavaScript
4
star
21

testing-vue-book-ru

4
star
22

MyWeather

Winner multidevice app made in FireMonkey for the 1st app challenge of Embarcadero Technologies
Pascal
4
star
23

egghead-lessons

JavaScript
4
star
24

MP3PlayerJS

Web-based MP3 player made using MVC pattern in vanilla js (plain javascript)
JavaScript
3
star
25

reactive-grocery-app

TypeScript
3
star
26

angular-bulma

Angular 2 UI component library on top of Bulma css framework
TypeScript
3
star
27

frontend-libs-medley

Vite best-practise example on creating a frontend library for Vue, React and Svelte
JavaScript
3
star
28

GaTe

Strategy and platform 2.5D videogame made in C++ and SFML
C++
2
star
29

testing-vue-book-es

2
star
30

Footle

Reservation system for busy people
TypeScript
2
star
31

TreeXplorer

Web-based file explorer made in plain Javascript and. Uses MVC, Browserify and CommonJS for structure.
JavaScript
2
star
32

gridsome-blog-example

An example on using Gridsome to create a blog
Vue
2
star
33

strapi-nuxt

JavaScript
1
star
34

awesome-resources

Personal list of curated resources
1
star
35

vue-simple-starter

Simple Vue.js starter using Poi
JavaScript
1
star
36

RelaxCoach

Simple project which is a prototype for a breathing techniques & heart-rate measurement applications, made with AngularJS
CSS
1
star
37

frontcast

A FrontEnd screencast platform
Vue
1
star
38

pruebasph1

Repositorio para pruebas de ph1
JavaScript
1
star
39

IRC-nw.js-chat

IRC chat made in nw.js (node.js based platform that creates cross-platform desktop apps)
CSS
1
star
40

Egghead_lesson-TypeScript_library_starter

Code for the typescript library starter lessons
JavaScript
1
star
41

Footle_deprecated

Reservation system for busy people
JavaScript
1
star
42

ClockMVCBrowserify

Simple Clock MVC project that uses Browserify to organize javacript files
JavaScript
1
star
43

MyWeb

Repo for my Website.
CSS
1
star
44

GCB-creator-lujan

Versión que añade otro tipo de actividad basada en iframes
JavaScript
1
star
45

Portfolio-client

TypeScript
1
star
46

WebBooks-project-Multimedia-Engineering

WebBooks application made for HyperMedia Development on Multimedia Engineering Degree
CSS
1
star
47

ObserverJS

Simple Observer pattern implementation to use it in hierarchy made in plain javascript
JavaScript
1
star
48

RxJS-FRP-talk

Slides of my talk "RxJS and FRP"
CSS
1
star
49

unnamed-server

TypeScript
1
star
50

DBCityFinder

Web-based project that uses DBpedia and SparQL in order to search and filter cities
JavaScript
1
star
51

Fullstack-scaffolding

Generated scaffolding project
JavaScript
1
star
52

AvadaLESS

Light framework and utils library made on LESS
CSS
1
star
53

TripMinder

Repositorio oficial para el TFG TripMinder
JavaScript
1
star
54

APitems

Analytics and charts webapp made for 2nd LOL API Challenge
JavaScript
1
star