问题
I am learning how Gatsby works and have got a website with 2 pages, both having hyperlinks to each other.
Since gatsby compiles a website to static pages with javascript bundles, I would expect html link click event to trigger page request to the server to load the second
page. However, I do not see such a request. The website behaves like single-page application loaded from the first
page. Link click does not cause network page request for the second
page. At the same time, I can see that the server responds on the request to the second
page correctly. In this case the second
page is loaded and navigation to the first
page via link click does not cause HTTP request too.
Is it by design? Could you please clarify what is actually happening in the compiled website?
If such single-page behavior is by design, I wonder how much negatively it impacts search-engine crawlers? I thought that single-page applications are not very good for indexing by google bot, etc..
Also, what if my pages are quite big (let's say rendered from markdown books or similar)? I would expect that single-page application would not be very optimal to load everything at once. What magic is applied by Gatsby in this case?
回答1:
Yes Gatsby is single-page website and yes it is also a multi-page website. Gatsby pre-renders individual pages as html files and also compiles corresponding react code into bundles.
On cold start any given page loads into the browser like any other static page, fast and SEO friendly. Once a static page is loaded, react code is bootstrapped and effectively runs the show ('a la' single-page app style). Pretty clever huh? However, only needed js bundles are fetched from the server (sometimes pre-fetched as well for speed).
Gatsby is really nothing more then a clever server rendered html react app that understands content types.
来源:https://stackoverflow.com/questions/46680835/clarification-on-gatsby-page-load-network-request