Giter VIP home page Giter VIP logo

Comments (15)

ivopetkov avatar ivopetkov commented on May 26, 2024

Why do you think it is loaded twice?

from responsively-lazy.

phun-ky avatar phun-ky commented on May 26, 2024

Because the Network tab indicates it:

screenshot from 2016-08-25 10-50-04

The produced code from responsively-lazy (when images are loaded):

<img class="responsively-lazy" data-srcset="person.png?a5d4227fb0532c90a39d82c366e571a6 480w" src="person-min.png?5cf834969a2582645e2c547bb22bc33f" srcset="person.png?a5d4227fb0532c90a39d82c366e571a6">

The code in the html (before lazy loading):

<img class="responsively-lazy" src="person-min.png" data-srcset="person.png" srcset="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" />

from responsively-lazy.

ivopetkov avatar ivopetkov commented on May 26, 2024

Can you please install v2.0.0 and try again.

from responsively-lazy.

phun-ky avatar phun-ky commented on May 26, 2024

I've already installed the latest from your git repo, and I still have
the same results.

from responsively-lazy.

ivopetkov avatar ivopetkov commented on May 26, 2024

Can you please send me another screenshot of your Network tab and make the 4th column slightly bigger, so that the whole content is visible.

from responsively-lazy.

phun-ky avatar phun-ky commented on May 26, 2024

@ivopetkov Oh, dang. I didn't respond to this. 😞 , sorry :(

Here is the screenshot, this is from a "hard refresh"

screenshot from 2017-03-02 12-47-06

soft refresh:

screenshot from 2017-03-02 12-48-42

from responsively-lazy.

ymnj avatar ymnj commented on May 26, 2024

@phun-ky Where you able to solve this issue. I'm running into the same problem.

from responsively-lazy.

phun-ky avatar phun-ky commented on May 26, 2024

@ivopetkov here is another example:

screenshot from 2017-03-30 11-03-31

The login.jpg image is set as the src, blurry is set to srcset and data-srcset is ${login} 960w, ${login2} 1920w, ${login3} 3840w

Tbh, this ${login} 960w, ${login2} 1920w, ${login3} 3840w should probably based on the correct sizes of the files: ${login} 1440w, ${login2} 2880w, ${login3} 4320w

Same setup, different zoom:

screenshot from 2017-03-30 11-06-13

I will add a video of the network tab so you can see. This video recording is from windows chrome, and I see that the second version of the same image are downloaded after the first version of the image is downloaded.

https://www.youtube.com/watch?v=sUSlBC8DbdY&feature=youtu.be

ALL PROVIDED EXAMPLES ARE FROM LINUX CHROME UNLESS OTHER IS SPECIFIED

In IE Edge, I get just the login.jpg. (as expected (?))

@ymnj have not solved this yet

from responsively-lazy.

ivopetkov avatar ivopetkov commented on May 26, 2024

I wanted a screenshot with a larger 4th column, so it's clear who is the initiator of the requests. In your screenshots and video the values responsivelyLazy.js, preact.js, vendors.js and Other at shown. I'll review again the images loading code in Responsively Lazy, but I believe in this case the reason for double loading are the other libraries you use. I'd recommend a deeper dive into their's code to see what and why they do.

from responsively-lazy.

phun-ky avatar phun-ky commented on May 26, 2024

A side note: I think that the desired usage of this module is not quite compatible with a react + redux SPA, since it's not quite clear on how I can control the initialisation of the module.

But here's how I've set it up, and the culprit is the re-render, I assume:

I've created a component, ResponsiveImage, that takes in the required params to operate, and sets an is-loaded class to it via setState. This means that the order of what is happening in the last given scenario (one image) is like this:

  1. Image renders
  2. Image is loaded (downloaded and displayed)
  3. onLoad is fired
  4. setState sets className, forces a re-render
  5. Image renders again
  6. Image is loaded (downloaded and displayed)
  7. onLoad is fired, nothing happens (since imageLoaded is not changed)

EDIT: with this screenshot, you see that it is responsively lazy that initiates it:
screenshot from 2017-03-31 10-09-37

And it's referring to https://github.com/ivopetkov/responsively-lazy/blob/master/responsivelyLazy.js#L108 and https://github.com/ivopetkov/responsively-lazy/blob/master/responsivelyLazy.js#L119

EDIT 2: In light of the new screenshot above, it is unlikely that the culprit of this issue is react or the re-rendering of the component. It is not the default browser behaviour to download an image with the same URL twice or more if it exist in the DOM or in the cache. Even if you insert two DOM-nodes with the same image on the same time, the image is not downloaded twice. So it has to be something with the caching or that the module (responsively lazy) do something with the URLs. (Or downloaded in an other way than through DOM-nodes)

from responsively-lazy.

ivopetkov avatar ivopetkov commented on May 26, 2024

Thanks. I think I have a solution. I'll write you back soon.

from responsively-lazy.

ivopetkov avatar ivopetkov commented on May 26, 2024

I've made a fix. Can you please download the JS code from the master branch and test on your environment.

from responsively-lazy.

phun-ky avatar phun-ky commented on May 26, 2024

screenshot from 2017-03-31 11-03-21

Looks much better! Please publish the fix to npm aswell ;)

from responsively-lazy.

selbekk avatar selbekk commented on May 26, 2024

Great job guys πŸ‘

from responsively-lazy.

ivopetkov avatar ivopetkov commented on May 26, 2024

v2.0.1 is on npm now.

from responsively-lazy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.