which modern JS framework offers component level lazy loading? Angular offers only route based lazy loading, which as is limited as the article pointed out.
For React, you can use React Loadable (https://github.com/jamiebuilds/react-loadable) that provides a Higher Order Component and Server Side rendering.
class Loader extends React.Component {
state = {
Component: null
};
componentWillMount() {
import('./Component').then(Component => {
this.setState({ Component });
});
}
render() {
const { Component } = this.state;
if (!Component) {
return <div>Loading...</div>;
} else {
return <Component/>;
};
}
}
Might want to add a few lines of error handling for production use, but that is pretty much all you need.https://blog.angularindepth.com/dynamically-loading-componen...