foreword

When developing the SSR website, I believe that you will encounter many problems more or less, but after understanding the essence of the SSR website, these are not problems. I will share my summary below, hoping to help everyone!

Summarize

Take next.js as an example

1. When the page is loaded for the first time or jumps to a page or refreshes the page, it will first get the data in the getServerSideProps method and then render it to the client browser

2. The data in the getServerSideProps method will all be cached in the client browser __NEXT_DATA__, so other pages that need this data do not need to request it, and can take it directly.

3. The getServerSideProps interface requests to pass the cookie from the context. After the request, if the background interface has set-cookie, it must be brought back to the client browser from ctx.res.setHeader.set-cookie

4. The data of getServerSideProps can be injected into the client browser, but the data of the client cannot be injected into the server. For example: after you click login, the information returned to the user after requesting the interface is the data obtained by the client. At this time, you refresh the page Login information will be lost, why? Because the client data server (when refreshing the page and entering the getServerSideProps method) cannot get it, that is why the developer should store the login information such as token in the cookie, and refresh the page to get it!


Awbeci
3.1k 声望212 粉丝

Awbeci