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

Question about pre-loading image files #2597

Closed
alleroux opened this issue Jun 22, 2017 · 3 comments
Closed

Question about pre-loading image files #2597

alleroux opened this issue Jun 22, 2017 · 3 comments

Comments

@alleroux
Copy link

I am importing image files using import so they are being properly included. I'm looking to pre-load some of the image files when the app loads because they are somewhat large and take a few seconds to load even after compressing them. Does create-react-app already have a package that can do this or is there a recommended package to use?

@heyimalex
Copy link
Contributor

Pretty sure it's not built in and there's no package, but the import resolves to the final path of the file so just preload however you normally would.

import logo from './logo.png';

function preloadImage(url) {
    const img = new Image();
    img.src = url;
}

preloadImage(logo);

@alleroux
Copy link
Author

Thanks. If I can't find a suitable package to do it I'll just do that.

@gaearon
Copy link
Contributor

gaearon commented Jun 26, 2017

Yep, that's the recommended approach.

@gaearon gaearon closed this as completed Jun 26, 2017
@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants