--- description: Next.js can handle data fetching in multiple ways for server-rendered and static pages. Learn how it works here. --- # Data fetching Next.js has 2 pre-rendering modes built-in: - [Static Generation](#static-generation) - [Server-side rendering](#server-side-rendering) You can learn more about the differences in the [pages section](/docs/basic-features/pages.md#pre-rendering). These rendering modes are tightly coupled to the way that you do data fetching. In Next.js data fetching generally happens at the page level. There are multiple reasons for this: - Avoid data fetching waterfalls, having to render then wait then render etc. - When pre-rendering React needs to have all data available before rendering. ## Static Generation By default Next.js pages that don't use [`getInitialProps`](/docs/api-reference/data-fetching/getInitialProps.md) get rendered to static HTML at `next build` time. This is useful for, as an example, dashboards that have a lot of dynamic data that depends on a specific user. You might not want to server-render that content but instead load the data client-side. For this particular use case [ZEIT](https://zeit.co) has created a data-fetching library called [SWR](https://github.com/zeit/swr). ```jsx // This page doesn't define `getInitialProps`. // Next.js will export the page to HTML at build time with the loading state // When the page is loaded in the browser SWR will fetch the data // Using the defined fetcher function import fetch from 'unfetch' import useSWR from 'swr' const API_URL = 'https://api.github.com' async function fetcher(path) { const res = await fetch(API_URL + path) const json = await res.json() return json } function HomePage() { const { data, error } = useSWR('/repos/zeit/next.js', fetcher) if (error) return