Reputation: 21
I am working on a React application that was built using SSR for SEO purposes. How does SSR with NextJS work? The requests must be being made from somewhere; if not the browser, then where? Thank you!
Upvotes: 2
Views: 9145
Reputation: 123
You are most probably using getInitialProps
for data fetching.
If so, you don't see the requests in your network tab on first page load because they are done on the server side. While if you navigate somewhere from this page after its initial load and then go back to the page needed, you'll see your requets in network tab. That is because the following data-fetching is done by NextJS on the client-side (from your browser).
For more info you can refer to the docs: https://nextjs.org/docs/api-reference/data-fetching/getInitialProps
getInitialProps is used to asynchronously fetch some data, which then populates props.
For the initial page load, getInitialProps will run on the server only. getInitialProps will then run on the client when navigating to a different route via the next/link component or by using next/router. However, if getInitialProps is used in a custom _app.js, and the page being navigated to implements getServerSideProps, then getInitialProps will run on the server.
Upvotes: 8