Question about server side rendering
enbits opened this issue · comments
I noticed on the example website that comes with the kit that if you go to a route lets say 'about' it reloads the whole page. Is this by design to implement server side rendering on every route change?
Hey @enbits thanks for getting in touch!
This is by design. When I built this boilerplate, I wanted to ensure that it could be used when building huge apps. One of the biggest I've worked on had a few hundred containers and a few dozen routes.
With apps of this size, the size of your bundle can be a huge performance bottleneck. We take the approach of chunking the bundle and using lazy loading of chunks at each route to minimize the amount of work that the browser needs to do on the initial load. In other words, the browser is only loading the part of the bundle that it needs when you visit a route.
With everything in Computer Science, there is a tradeoff to this approach, which is that you have to reload each chunk on each route transition. There are a few methods that I have found to try to solve this. One of my favorites is to use Service worker to cache the bundles in an effort minimize the amount of time it takes to load the bundle at each route transition.
In fact this boilerplate has some configuration if you want to use Service Worker. One requirement for that, however, is that you are running your server behind SSL, which the demo site is not. The initial flash of un-styled content you are seeing is based on the fact that only some of the css is server-rendered. The rest of it needs to be loaded from the bundle when you transition routes. Also in some cases, you need to make an http request on route transitions, which will delay the rendering even more. It's a tough problem to solve, for sure!
By the way, I have written a few articles on my blog about the approaches I've taken to try to solve performance issues in the project. Part 1 goes into a lot of this stuff and part 2 touches on some other client-side optimizations, such as reselect and immutable.
Please let me know if this answers your question. I'd be happy to try to explain it more in depth if you want.
Thanks Ryan for the detailed response.
Didn't realize you were using classic anchors on the Navbar component, but if react-router links are used instead you get client side rendering. Its really nice to have both options working out of the box.
Also the cli generator is very good. You made a complete framework, very good!
Yeah, the grommet Anchor component recently added a path property that uses react router behind the scenes. Sorry forgot to mention that, it's been a while since I've touched this demo site. I'll have to refactor the navbar at some point to use the path vs href. I'd like to upgrade to react router 4 soon anyways!
Glad it's working out for you and that you like the generators!
Hey @enbits , I am going to close this issue, but feel free to keep the conversation going or reopen it if you have any more questions.