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

When opening the LightBox, it loads every image. #26

Open
spaceguy101 opened this issue Feb 27, 2021 · 2 comments
Open

When opening the LightBox, it loads every image. #26

spaceguy101 opened this issue Feb 27, 2021 · 2 comments

Comments

@spaceguy101
Copy link

On such implementation

      <Lightbox
        currentImageIndex={currentImage}
        setCurrentIndex={setCurrentImage}
        isOpen={viewerIsOpen}
        onClose={() => closeLightbox()}
        images={photoGallery.photos}
      />

When viewerIsOpen is true, the modal opens and starts downloading every elements of images.

If there is a lot of elements, it slows down the browser a lot, especially on mobile.

Is there a way to download only the visible image or maybe lazy load only the few next images ?

@guillenjs
Copy link

I am experiencing a similar issue. It seems like if there are too many images the lightbox won't open until all the images are loading. Causing it to seem like the feature is not working to the end user.

I know that it works though because once images are loaded the lightbox works. Is there a solution for this?

@andreynovikov
Copy link

As a workaround I've added loading: 'lazy' to every image entry in array like that:

const images = [
  {
    src: 'https://timellenberger.com/static/blog-content/dark-mode/win10-dark-mode.jpg',
    loading: 'lazy'
  },
  {
    src: 'https://timellenberger.com/static/blog-content/dark-mode/macos-dark-mode.png',
    loading: 'lazy'
  }
];

LightBox propagates all props to <img> element and thus enables native browser lazy loading. I've tested it in desktop Chrome: when LightBox is opened only one extra image is loaded by browser. Looks perfect for me. Have not tested it on mobile yet.

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

No branches or pull requests

3 participants