vue-lazyload icon indicating copy to clipboard operation
vue-lazyload copied to clipboard

initial image is showing up as "not found" with nuxt

Open miteyema opened this issue 5 years ago • 14 comments

Hi

When implementing vue-lazyload in nuxt, I see the following result in my browser (please also refer to the picture below):

  1. image is "not found" as the alt text is shown
  2. the loading placeholder image is shown
  3. the actual image is shown

problem

Why is it that I see this first step, i.e. the image that is not being found? This is very weird behaviour and I do not manage to solve this problem.

This is my config:

lazyload.client.js plugin:

import Vue from 'vue'
import VueLazyload from 'vue-lazyload'

import loading from '../assets/images/placeholder.png'

Vue.use(VueLazyload, {
  loading
})

And I have this in my template:

<template functional>
  <figure class="image is-3by2">
    <img v-lazy="props.src" :alt="props.alt" />
  </figure>
</template>

<script>
export default {
  props: {
    src: {
      type: String,
      required: true
    },
    alt: {
      type: String,
      required: true
    }
  }
}
</script>

nuxt.config.js file excerpt:

export default {
  mode: 'universal',
  plugins: [
    '~/plugins/lazyload.client.js'
  ],
  ...
}
````

miteyema avatar Nov 05 '19 00:11 miteyema

Hi @miteyema ,

Did you manage to find a solution for this? I have run into exactly the same problem.

jrah avatar Nov 25 '19 01:11 jrah

@jrah No, sorry, I still have that problem...

miteyema avatar Nov 25 '19 01:11 miteyema

have you tried enabling client side rendering for that part with <client-only> ?

mstaack avatar Nov 29 '19 19:11 mstaack

@mstaack Visually that works, but won't that have issues with SEO and the alt tag?

jrah avatar Nov 30 '19 17:11 jrah

I had the same issue - because of browser adblock plugin ;)

filipwronski avatar Jan 15 '20 10:01 filipwronski

Having same issue, I opened it on incognito with no browser adblock but the issue still persist @filipwronski

have you tried enabling client side rendering for that part with ? This works, but yes, it's going to affect SEO I think?

Anyone has a solution for it now?

blek-id avatar Mar 18 '20 08:03 blek-id

Up ?

MatteoGauthier avatar Apr 10 '20 18:04 MatteoGauthier

I'm getting the same issue, but only when first loading a page. It no longer occurs once you navigate to different pages in-app.

AmrKafina avatar Apr 14 '20 14:04 AmrKafina

One work around that worked for me is set the src attribute on the img tag to the placeholder image (the one used for loading). <img v-lazy="{loading: 'loading.gif', src: 'src.png'}" :src="loading.gif" :alt="props.alt" />

prateekbaheti avatar Jun 15 '20 10:06 prateekbaheti

@prateekbaheti That's a working solution, but I would personally not use that. If for whichever reason the plugin/javascript does not work, the user is stuck with the loading picture. I also don't know how this affects SEO...

miteyema avatar Jun 15 '20 23:06 miteyema

no other solutions for this?

Martin7mind avatar Jun 16 '20 08:06 Martin7mind

img:not([src]) { display: none; }

this seems to work in chrome, to hide the broken images until the javascript set the src-attribute

Martin7mind avatar Jun 16 '20 09:06 Martin7mind

you set src="image-lazyload.jpg"

minhtaicdv1995 avatar Sep 14 '20 09:09 minhtaicdv1995

I think, showing the "loading.jpg" place holder is not an option since you still getting images without proper src from server which will impact SEO (crawlers which work without good JS support will only see the content from your server which don't have proper src's)

arnfox avatar Jul 07 '21 17:07 arnfox