View source not displaying dynamic content

后端 未结 3 979
臣服心动
臣服心动 2021-01-25 05:59

I am making very simple next js application, where everything is working fine but except the view source.

I am making a promise and there is a delay in retrieving conten

3条回答
  •  既然无缘
    2021-01-25 06:46

    Other answers already quite clear telling you the reason why your dynamic content doesn't appear on source code.

    First, there are two kinds of rendering: server side and client side.

    • Server side / SSR is when your server render your app and then send it to the client (browser).

    • Client side / CSR is when your app reach the browser, it will be rendered again (but this time only render what is necessary if you have activated SSR, which NextJS has as default).

    If you want your dynamic content to be appear at the source code, you should call your api on the server side like @Nikolai Kiselev has mentioned. NextJS provides function getServerSideProps()(for the component level) to be used if developers want to fetch info on the server side.

    If you put your profile() function as a page, you could also use getInitialProps() function to fetch your api from server side.

    Please take a look on NextJS doc, they have given the examples you need.

提交回复
热议问题