Jump to content
Search Community

Lazy load ScrollTrigger demo loading images twice

ekfuhrmann test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

I was playing around with your lazy loading scrollTrigger demo, and realized that it seems to be duplicating the high-res image download twice, essentially doubling the size of the page.

Not being entirely familiar with the methods being used for this effect, I was unable to figure out how to prevent it from double triggering.

See the Pen OJMaEOP?editors=0010 by GreenSock (@GreenSock) on CodePen

Link to comment
Share on other sites

Sorry, let me rephrase a bit. I added this exact codepen to a local project I'm working on that is using local files, and I'm still getting hit with downloading the files twice when checking the networking tab of developer console.

 

For example it looks like this, where the bedroom-pre.jpg is the low-fi image, while the bedroom.jpg is the hi-fi image.

image.png.8a0e32ba3a2013e209db2604cef15b71.png

 

As you can see, it's getting served up twice, and I'm seeing this happen in the demo on codepen as well, albeit it's a bit harder to parse there due to the picsum hosting.

 

My <img/> markup looks like this:

<img class='lazy' src='bedroom-pre.jpg' data-src='bedroom.jpg' alt='' />

And I'm using the identical JS found in the codepen.

 

Hope that helps clarify a bit?

Link to comment
Share on other sites

  • Solution

I think that's simply because it has to swap the src on both images so that it can do the crossfade when the big version loads. And the browser shouldn't actually need to download the whole thing again - it's simply pulling it from its cache. 

  • Like 1
Link to comment
Share on other sites

Ah I see. So the issue was that I had Disabled cache toggled on in the Network tab, which was causing it to re-download the image. Under normal circumstances, to your point, it would pull from the cache and not re-download.

 

Thanks for helping with that.

Link to comment
Share on other sites

4 minutes ago, OSUblake said:

Are you even using a server? And does it have the correct headers? You shouldn't see it appear more than once in the network tab. Once it's cached it will show that.

 

image.png


  

 

I was running a localhost, but the issue was due to me having Disable cache enabled in my developer tools. Once disabled, it was displaying once.

 

No surprise, it was a mistake on my part.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...