问题描述:

I have an app written in reactjs, it's pretty fast when the components are rendered, but it's too slow for it to be rendered. On computer, it takes about 2 seconds, but on mobile, it takes around 8 seconds for the page to be rendered, it's really too slow.

Is there any generic methods to improve loading time for the website?

I used chrome timeline to analyze the performance. I saw that lots of time was spent by browser.js. I was wondering if converting reactjs jsx to javascript will help.

I also saw there is a long pause before the doms are shown, I am not sure what the browser does during this time and how to solve this.

网友答案:

You should definitely pre-compile your React code for production. Also it is very important to set your process.env.NODE_ENV to production. This will speed up general and initial rendering by a lot (even more so for server-side rendering). You could use the browserify plugin envify for this, or the corresponding webpack plugin (depending on your stack).

Also I recommend this conference talk, which includes lots of other minor/major rendering speed-ups: https://www.youtube.com/watch?v=PnpfGy7q96U

相关阅读:
Top