question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] add v-img lazyload prop - only start loading src if element is visible

See original GitHub issue

What problem does this feature solve?

Option to lazyload images only if the content is visible Google “Pagespeed Insights” would like to prioritize visible content.

https://developers.google.com/speed/pagespeed/insights/?url=https%3A%2F%2Fvuetifyjs.com%2Fen%2Fcomponents%2Fimages

It would optimize network roundtrips and only loads images which are in visible area

What is your proposed solution?

Add a prop to enable lazyload - only load images which are inside of visible content.

Two references of projects where this technique is applied:

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:15
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
dillionvermacommented, Jul 18, 2019

A short and sweet solution for this using Interaction Observer API.

<template>
  <v-img :src="srcUrl" />
</template>

<script>
export default {
  data: () => ({ 
    observer: null, 
    intersected: false,
    my_url: "https://myurl.com"
  }),
  computed: {
    srcUrl() {
      return this.intersected ? this.my_url : '';
    }
  },
  mounted() {
    this.observer = new IntersectionObserver(entries => {
      const image = entries[0];
      if (image.isIntersecting) {
        this.intersected = true;
        this.observer.disconnect();
      }
    });

    this.observer.observe(this.$el);
  },
  destroyed() {
    this.observer.disconnect();
  }
}
</script>

Works flawlessly with no extra dependencies.

Credit to: https://alligator.io/vuejs/lazy-image/

5reactions
MatthewArycommented, Jan 25, 2019

DId this make it into 1.3.0? If so the docs don’t reflect it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Browser-level image lazy loading for the web - web.dev
This video shows a demo of the feature: In Chrome 76 onwards, you can use the loading attribute to lazy-load images without the...
Read more >
Lazy loading - Web performance | MDN
Lazy loading is a strategy to identify resources as non-blocking (non-critical) and load these only when needed. It's a way to shorten the ......
Read more >
Lazy Loading Images – The Complete Guide - ImageKit.io
Everything about Image Lazy loading - what is it, why is it important, ... We trigger the load for these images when they...
Read more >
A Deep Dive into Native Lazy-Loading for Images and Frames
The initial, server-side HTML response includes an img element without the src attribute so the browser does not load any data. Instead, the ......
Read more >
Various Ways to Lazy Loading Images on a Website - Medium
Images are the most requested asset type for most websites. ... loading=”lazy” means image load only if it's near or visible on viewport....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found