| ▲ | user34283 3 days ago | |
You cannot load any data in a regular React application before you loaded both React and your React components that trigger the fetch. If you use code splitting, your initial bundle size can be smaller, yes. That's about it. I guess in theory you can hack together static loading skeletons that you then remove when React loaded your initial bundle, but that's certainly far from a common approach. By that standard, the vast majority of JS bundles would be "broken". | ||
| ▲ | zarzavat a day ago | parent [-] | |
> You cannot load any data in a regular React application before you loaded both React and your React components that trigger the fetch. You totally can! Don't call fetch directly from a component - it's brittle. Write a hook to abstract that into one place. In your hook you can support prefetching by awaiting the promise you fired before you loaded your JS bundle (if you don't want to modify the server), or else take advantage of the browser cache. In this way your data and code can load in parallel. Is it common? Not really. But it's a technique that is in the toolbox of a conscientious webdev. | ||