Skip to content

Commit f313dbb

Browse files
ascorbicTiffany Le-Nguyen
and
Tiffany Le-Nguyen
authored
chore: document ISR (#986)
* chore: document ISR * Apply suggestions from code review Co-authored-by: Tiffany Le-Nguyen <[email protected]> Co-authored-by: Tiffany Le-Nguyen <[email protected]>
1 parent 1da95d0 commit f313dbb

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

docs/isr.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
## Incremental Static Regeneration (ISR)
2+
3+
[Incremental static regeneration](https://vercel.com/docs/concepts/next.js/incremental-static-regeneration) is a feature
4+
of Next.js that allows pages to be updated after a site has been built and deployed. It is now fully supported in
5+
Netlify by the Essential Next.js plugin, meaning large sites can update pages without needing to rebuild the entire
6+
site. Unlike server-side rendered pages, the page is not rebuilt for each user, so they load quickly, but unlike
7+
statically-generated pages they can be periodically updated with new content without a new deploy.
8+
9+
### Using ISR on Netlify
10+
11+
ISR on Netlify is implemented with [On Demand Builders](https://docs.netlify.com/configure-builds/on-demand-builders/),
12+
using the TTL feature. You can enable ISR for a page by returning a value for `revalidate` from the `getStaticProps`
13+
function. This value is the number of seconds for which the content will be considered fresh. If a request arrives for a
14+
page after the `revalidate` period has elapsed, the page will be regenerated. ISR uses a "stale while revalidate"
15+
strategy, meaning that the visitor still receives the stale content, but it is regenerated in the background ready for
16+
the next request. The generated page is persisted globally, so is available to all visitors wherever they are in the
17+
world. It is also cached in the global Netlify CDN so responses are fast.
18+
19+
The minimum value for `revalidate` is 60 seconds, and any value less than that will be rounded-up to 60 seconds. After a
20+
request is made for stale content, the page will be regenerated in the background and immediately persisted globally,
21+
but it can take up to 60 seconds before the new content is then updated in all CDN nodes if they already had a cached
22+
copy.
23+
24+
If a new deploy is made, all persisted pages and CDN cached pages will be invalidated so that conflicts are avoided. If
25+
this did not happen, a stale HTML page might make a request for an asset that no longer exists in the new deploy. By
26+
invalidating all persisted pages, you can be confident that this will never happen and that deploys remain atomic.
27+
28+
### Alternatives to ISR
29+
30+
ISR is best for situations where there are regular updates to content throughout the day, particularly you don't have
31+
control over when it happens. It is less ideal in situations such as a CMS with incremental updates where you can have
32+
the CMS trigger a deploy when a page is added or edited. This offers the best performance and avoids unnecesary
33+
rebuilds.
34+
35+
### Static site generation
36+
37+
For high-traffic pages you can use
38+
[static generation](https://nextjs.org/docs/basic-features/data-fetching#getstaticprops-static-generation) without
39+
`revalidate`, which deploys static files directly to the CDN for maximum performance.
40+
41+
### Distributed persistent rendering
42+
43+
For less commonly-accessed content you can use return `fallback: "blocking"` from
44+
[`getStaticPaths`](https://nextjs.org/docs/basic-features/data-fetching#getstaticpaths-static-generation) and defer
45+
builds until the first request. This also uses On Demand Builders, but persists the built page until the next deploy.
46+
This is great for long-tail content and archives that don't change often but are not accessed often enough to justify
47+
statically-generating them at build time.

0 commit comments

Comments
 (0)