Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intersection Observer not working in Internet Explorer 11 #383

Closed
zmrhaljiri opened this issue Oct 12, 2019 · 8 comments
Closed

Intersection Observer not working in Internet Explorer 11 #383

zmrhaljiri opened this issue Oct 12, 2019 · 8 comments

Comments

@zmrhaljiri
Copy link

Describe the bug
When opening a page in Internet Explorer 11 with the Intersection Observer polyfill + lazyload libraries included, all lazy images (including background) are loaded at once on page load.

To Reproduce
Steps to reproduce the behavior:

Example 1: Normal images

  1. Open Internet Explorer 11
  2. Go to the official demo page with the Intersection Observer example
  3. Open the Network tab
  4. Refresh the page
  5. You can see all images are loaded at once

Example 2: Background images

  1. Open Internet Explorer 11
  2. Go to the example page I prepared, notice the Intersection Observer polyfill is included before the lazyload library
  3. Open the Network tab
  4. Refresh the page
  5. You can see all images are loaded at once

Expected behavior
Images are loaded only when they enter a viewport.

LazyLoad version

  • Version 12.1.0

Desktop (please complete the following information):

  • OS: Windows
  • Browser Internet Explorer
  • Version 11
@verlok
Copy link
Owner

verlok commented Oct 13, 2019

Hi @zmrhaljiri,
thank you for taking the time to open this issue.

It’s not a bug, it’s designed to work like this. If the browser doesn’t support IntersectionObserver, it loads all the images to make users see the images anyway.

If you require the same exact behaviour also in IE11, you should load a polyfill before loading LazyLoad. Find out how in the documentation (README file).

Before doing that, please consider that IE11 is not maintained anymore, and analyse how many users of your website browse it with IE11.

@zmrhaljiri
Copy link
Author

zmrhaljiri commented Oct 13, 2019

Hello @verlok,
thanks for the reply.

You are right, if the browser doesn't support Intersection Observer, then all the images are loaded. But if I understand it correctly, if the polyfill is loaded before LazyLoad is loaded, then it should work fine. Is that correct?

On the example page, you can see that the Intersection Observer polyfill is loaded before LazyLoad, so it should not load all the images at once, am I right or missing something here, please?

(Using IE11 is not my decision, I just have to :))

@oncode
Copy link

oncode commented Oct 15, 2019

Hi @verlok @zmrhaljiri
I just noticed the same issue. The problem is with the new way of checking if IntersectionObserver is supported added 17 days ago with this commit: 1023235

The last two tests are failing when using the w3c intersection-oberserver:

"intersectionRatio" in window.IntersectionObserverEntry.prototype;
"isIntersecting" in window.IntersectionObserverEntry.prototype;

For a quick solution I downgraded from version 12.1.0 to 12.0.1 with:

npm install vanilla-lazyload@12.0.1 --save --save-exact

When I import the library I also need to use import LazyLoad from 'vanilla-lazyload/dist/lazyload' (full path to dist) or else it won't work.

@verlok
Copy link
Owner

verlok commented Oct 17, 2019

Thanks for pointing this out.
I had a feeling that changing the way we detect IntersectionObserver it could break something.
I can roll it back eventually.
But why is the W3C IntersectionObserver polyfill missing those properties?

@verlok
Copy link
Owner

verlok commented Oct 17, 2019

Could you please tell me which version of the intersection observer polyfill you are using?

@oncode
Copy link

oncode commented Oct 17, 2019

@verlok Sure, I'm using the latest one 0.7.0. They seem to assign those properties in the constructor of IntersectionObserverEntry, not via prototype, that's why the lookup in the prototype is failing.

https://github.com/w3c/IntersectionObserver/blob/master/polyfill/intersection-observer.js#L64
https://github.com/w3c/IntersectionObserver/blob/master/polyfill/intersection-observer.js#L79

verlok added a commit that referenced this issue Oct 21, 2019
@verlok
Copy link
Owner

verlok commented Oct 21, 2019

Solved with 12.1.1

@verlok verlok closed this as completed Oct 21, 2019
@zmrhaljiri
Copy link
Author

Many thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants