Create-react-app: Question about pre-loading image files

Created on 23 Jun 2017  路  3Comments  路  Source: facebook/create-react-app

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?

question

Most helpful comment

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);

All 3 comments

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);

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

Yep, that's the recommended approach.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fson picture fson  路  3Comments

fson picture fson  路  3Comments

oltsa picture oltsa  路  3Comments

ap13p picture ap13p  路  3Comments

wereHamster picture wereHamster  路  3Comments