Gatsby's Client Side Routing - What Gatsby features do my client-rendered pages still benefit from?
Asked Answered
C

2

6

I built a small site that uses gatsby for static content, but then for some content that needs to be rendered on the client-side, I'm using client-only routes in gatsby.

I am not sure I fully understand how this works though - Say I have a Header, Footer & a font that I am using in my static site. On my client-only routes, I am using the same Header, Footer & font. Will I benefit at all from having used these elements in my statically components previously? Is the font being loaded anew, for example?

Basically, I would like to know what Gatsby-features my client-site content is losing out on now, and what I should maybe attend to a bit more, since Gatsby won't be handling this for me anymore. Especially in terms of pagespeed.

Chaldea answered 19/6, 2020 at 8:34 Comment(0)
P
0

Yes you should benefit from having used those components and fonts already.

The React components that are being re-used will already be in a JS bundle that you have shipped to the user and shouldn't need to be fetched again. Likewise with the font files - but these will be asset files - not in a JS bundle.

The best way to see what is being fetched will be to test it out in a browser.

  1. Load a static page
  2. Open the Network tab in dev tools
  3. Navigate to a client-only page and check for network activity

While those assets shouldn't be fetched twice I can imagine some instances where an incorrect setup would fetch them twice - so best to just double check.

Poul answered 4/12, 2020 at 9:23 Comment(0)
M
0

Will I benefit at all from having used these elements in my statically components previously?

The answer is yes. Gatsby works with @reach/router under the hood so you will have all benefits of it no matter if you use client-only routes or not.

In other words, the trickiest part of using client-only routes is the internal routing, for your site, in that scenario, Gatsby will handle the routing internally since it extends from @reach/router, so the shared components (header, footer, etc) will only be rendered on-demand and will be shared across your site, no matter if it's a client-only route or a static page.

I would like to know what Gatsby-features my client-site content is losing out on now, and what I should maybe attend to a bit more, since Gatsby won't be handling this for me anymore. Especially in terms of pagespeed.

Summarizing a lot, when a page loads, @reach/router looks at the path prop of each component nested under <Router />, and chooses one to render that best matches window.location. So you will only render the needed code on-demand.

In terms of page speed, your site won't be affected because the site keeps being "static" and pre-mounted once the build is done. The only "negative" part of using client-only routes (if you want to say that) is the SEO part since they won't be intercepted by Google, but, that's the reason why you are using client-only paths, in most of the cases you don't want to index those pages.

Moitoso answered 14/12, 2020 at 12:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.