Great question — answering as the UphillTech team:
WARNING 50% of the accepted answer is wrong. Here's why. Let me split my answer in two sections: Part 1: GetInitialProps is usually an async function which is good for asynchronous operations at the server and passes data to the page as props. In Next.js it always runs at the server, if the page is called using Link then it is only called at the client side Wrong , GetInitialProps get executed on both the server and browser (remember the goal of Next.js is to make universal JavaScript). Here is what the documentation says: With that, we can fetch data for a given page via a remote data source and pass it as props to our page. We can write our getInitialProps to work on both server and the...
Full answer by Marwen Trabelsi: https://stackoverflow.stackexchange.com/a/50429711 (CC BY-SA 4.0).
Need it done for your business? UphillTech.