Git Product home page Git Product logo

Comments (10)

neptunian avatar neptunian commented on July 21, 2024

@jossmac is this enhancement for preloading of the larger lightbox images or the gallery preview images?

from react-images.

jossmac avatar jossmac commented on July 21, 2024

@neptunian the larger lightbox images. The idea was to implement this with a Boolean prop preloadImages.

The idea was to loop over the images array and preload using new Image(). I have a working example in a commercial project where I've forked this component. Is it something you'd be interested in?

from react-images.

jossmac avatar jossmac commented on July 21, 2024

@neptunian it's worth mentioning that this component doesn't know about, and has no need for, the preview thumbnails. That can be handled elsewhere πŸ˜„

from react-images.

neptunian avatar neptunian commented on July 21, 2024

@jossmac right, just makin' sure ;) Just had someone open an issue in my gallery component about it (neptunian/react-photo-gallery#3). If you've got a working solution for it, be my guest! :)

from react-images.

neptunian avatar neptunian commented on July 21, 2024

@jossmac i'd be interested in doing this if you'd like to show me the working example you had in mind.

from react-images.

jossmac avatar jossmac commented on July 21, 2024

@neptunian thanks for the offer. I'd like to sort it out though

from react-images.

neptunian avatar neptunian commented on July 21, 2024

@jossmac sounds good.

from react-images.

GregoryPotdevin avatar GregoryPotdevin commented on July 21, 2024

Started using react-images and it fits my use case perfectly (keep control over the gallery, and use something else for the lightbox part). Preloading would be a huge plus for me as well.
Has anyone tried just rendering the previous and next images in a 0 width div and let the browser do the preloading ?

Something like

    renderPreloadImage(extraIndex) {
        const { images, currentImage } = this.props;
        const idx = currentImage + extraIndex
        if (!images || !images.length || idx < 0 || idx >= images.length) return null;

        const image = images[currentImage];

        let srcset;
        let sizes;

        if (image.srcset) {
            srcset = image.srcset.join();
            sizes = '100vw';
        }

        return (
                <img style={{
                        width: 0, height: 0
                    }}
                    sizes={sizes}
                    src={image.src}
                    srcSet={srcset}
                />
        );
    }

Used as

  <div className={classes.content}>
    {this.renderCloseBar()}
    {this.renderImages()}
    {this.state.isLoaded && this.renderPreloadImage(-1)}
    {this.state.isLoaded && this.renderPreloadImage(1)}
  </div>

(this.state.isLoaded could be used to keep track of if the current image is already loaded, to only preload once the image itself is loaded)

from react-images.

jossmac avatar jossmac commented on July 21, 2024

That's an interesting thought @GregoryPotdevin thanks for sharing. I have a plan for this that I'd really like to try out

I'm sorry for dropping this for so long, but I will pick it up and add it to my list for this week.

from react-images.

GregoryPotdevin avatar GregoryPotdevin commented on July 21, 2024

Great !

Another way to do it that would work with custom components (and not just image links) would be to render the normal previous/next but inside a hidden div. But I'm not sure how and when the different browsers preload images in hidden divs. A clean implementation with this idea could also provide scrolling animations when changing currentImage.

from react-images.

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.