Hey all,
I’m wondering what the best practice is for preloading and caching app assets? I’ve read the docs on Offline Support,Preloading & Caching Assets and https://docs.expo.io/versions/latest/sdk/app-loading.html, and I’m using the suggested approaches. However, I find that my app has quite a long startup time in spite of having fairly few assets (<1 mb, 16 files)
My asset folder structure is as follows:
assets
background
1 .png file
icons
10 .png files
pushbutton.png
splash.png
In my app.json
, I bundle all of these with "assetBundlePatterns": ["assets/**"]
My AppLoading
looks like this:
<AppLoading
startAsync={this.loadAndCacheAssets}
onFinish={this.setReady}
onError={this.handleLoadingError}
/>
and my loadAndCacheAssets
function:
export const loadAndCacheAssets = async () => {
// const imageAssets = cacheImages([
// 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png',
// require('./assets/images/circle.jpg'),
// ]);
const fontAssets = cacheFonts([
FontAwesome.font,
Foundation.font,
Ionicons.font,
SimpleLineIcons.font,
Octicons.font,
Entypo.font,
EvilIcons.font,
MaterialIcons.font,
MaterialCommunityIcons.font,
]);
await Promise.all([
// ...imageAssets,
...fontAssets,
]);
};
const cacheImages = images => {
return images.map(image => {
if (typeof image === 'string') {
return Image.prefetch(image);
} else {
return Asset.fromModule(image).downloadAsync();
}
});
};
const cacheFonts = fonts => {
return fonts.map(font => Font.loadAsync(font));
};
I intentionally included the outcommented code for caching images, seeing as all images should be bundled with the app due to the app.json
, right? Or did I misunderstand something?
Also, I’m not sure wether it’s a terrible idea to download the full font libs - does someone know how big these are, and if there’s some way to only download the icons I need?
In any case, I could understand why the above two issues could make the first app startup slow if my bundling isn’t set up right - but it continues to take around 7-10 seconds for a cold start?
Any advice would be much appreciated.