In Next.js, a route can be statically or dynamically rendered.
Static rendering (default) improves performance because all the rendering work is done ahead of time and can be served from a Content Delivery Network (CDN) geographically closer to the user.
|Data Fetching||Dynamic Functions||Rendering|
Note how, for a route to be statically rendered, the data requests are cached and there are no dynamic functions.
By default, Next.js will cache the result of
fetch() requests that do not specifically opt out of caching behavior. This means that fetch requests that do not set a
cache option will use the
If any fetch requests in the route use the
revalidate option, the route will be re-rendered statically during revalidation.
To learn more about caching data fetching requests, see the Caching and Revalidating page.
During static rendering, if a dynamic function or a dynamic
fetch() request (no caching) is discovered, Next.js will switch to dynamically rendering the whole route at request time. Any cached data requests can still be re-used during dynamic rendering.
Since the returned value of these functions cannot be known ahead of time, using them in a layout or page will force dynamic rendering at request time.
Dynamic data fetches are
fetch() requests that specifically opt out of caching behavior by setting the
cache option to
The caching options for all
fetch requests in a layout or page can also be set using the segment config object.
To learn more about Dynamic Data Fetching, see the Data Fetching page.