-
-
Notifications
You must be signed in to change notification settings - Fork 27k
Initial PageSpeed performance vs .js and .css bundles #1968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This recommendation is only useful for apps that aren’t fully constructed in JS so we don’t follow it. It definitely makes sense if your app is partially server rendered, but this not the case for CRA.
No, this is not the case. let TodoList = null;
class LazyTodoList extends Component {
constructor(props) {
super(props);
this.state = { isReady: TodoList !== null };
}
componentDidMount() {
require.ensure('./TodoList', () => {
TodoList = require('./TodoList').default;
if (!this.hasUnmounted) {
this.setState({ isReady: true });
}
});
}
componentWillUnmount() {
this.hasUnmounted = true;
}
render() {
return this.state.isReady ? <TodoList /> : <h1>Loading...</h1>;
}
} This will load It is a bit awkward to use componentDidMount() {
import('./TodoList').then(TodoList => {
if (!this.hasUnmounted) {
this.setState({ isReady: true });
}
});
} This will be supported in Hope this helps! |
Oh I see. Thank you very much for your devoted time on this. |
Concerned by the initial page load, I tried to put my app into testers like PageSpeed Insights. Though I understand I am not the best developer out there and can definitely review things, what surprises me is that my overall score gets mostly drained by
Google recommends this :
I understand that some part of the Javascript and Css could stay like this (due to framework nature of building the page based on javascript). However, a big chunk of the javascript does NOT participate to initial page load, rather they could be called separately or execute asynchronously.
In some related issue, I found several alusions to the
require.ensure()
function provided by webpack. My concern is that I am a newbie here and doesn't seem to oversee how to implement it in practice so that workflow stays equal.After reading some docs, I found that basically, I should do something like:
Eventually, this pattern will split my Javascript into 2 separate bundles (tested, it works). However, this implies very poor old fashioned experience of javascript (callback hell?) because as I understand, I should but all my components within the callback of
require.ensure()
...I love
create-react-app
as a developer, but I don't think my users will feel the same passion if I can't boost their experience and ask them to wait for AAAAAAAALLLLLLLLL my files to be downloaded.So after hours searching and fighting my pagespeed score, I surrender myself to you guys:
how do you handle pagespeed issues and particularly blocking resources ? Do you use
require.ensure()
? In which context? How do you handle big .js and .css bundle?Some examples would be more than appreciated.
Thanks
The text was updated successfully, but these errors were encountered: