Reputation: 1
I have been looking for a good solution to load async react components on demand at matched route without Webpack import, System.import, require.ensure, ...
I want to avoid Webpack footprints in client-side code.
On Server I fetch all routes and render matched locations as static HTML/JS. Like classic SSR.
wrap=true
over ajaxwrap=true
render c1.js on server to fetch data (universal ajax) from DBThis way i have a small entry file and could:
https://host
and load component (/path) on demandhttps://host/path
on entry and render compleate components (no async)https://host/path
with RR4 and fetch and render async component(s)use browser history (back-forward) without requests for data or components (both exist in Redux store and script tag)
Be able to use component with pagination (load more data and reuse fetched component)
My thoughts on this:
Render async components direct to Dom instead cache them in script tag will lose component code on unmount parent Component (because async component not exist in main.bundle.js)
Is it bad practice to split react code over independent bundles?
`<script src=bundle.js /><script>*c1.js* code</script>`
<App/>
or <Home/>
)
Upvotes: 0
Views: 1192
Reputation: 275
I don't see why you would have to use any Webpack specific code in your client-side code? The below is from a library called react-loadable
. The only Webpack specific hack you can do is put a Webpack specific comment near the import to make it use the name specified.
import Loadable from 'react-loadable';
import Loading from './my-loading-component';
const LoadableComponent = Loadable({
loader: () => import('./my-component'),
loading: Loading,
});
export default class App extends React.Component {
render() {
return <LoadableComponent/>;
}
}
This is the library I would suggest you start using when you want to do code-splitting. Especially if you also want to do SSR. It has a few utility classes to help you with that.
Upvotes: 0