Skip to content

Commit 8e64ba7

Browse files
committed
End of part 8
1 parent 8964c83 commit 8e64ba7

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/app/(SSR)/isr/page.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { UnsplashImage } from "@/models/unsplash-image";
2+
import Image from "next/image";
3+
import Link from "next/link";
4+
import { Alert } from "@/components/bootstrap";
5+
6+
export const metadata = {
7+
title: "Incremental Static Regeneration - NextJS 13.4 Image Gallery",
8+
}
9+
10+
export const revalidate = 15;
11+
12+
export default async function Page() {
13+
const response = await fetch("https://api.unsplash.com/photos/random?client_id=" + process.env.UNSPLASH_ACCESS_KEY,
14+
{
15+
// next: { revalidate: 15 }
16+
}
17+
);
18+
const image: UnsplashImage = await response.json();
19+
20+
const width = Math.min(500, image.width);
21+
const height = (width / image.width) * image.height;
22+
23+
return (
24+
<div className="d-flex flex-column align-items-center">
25+
<Alert>
26+
This page uses <strong>incremental static regeneration</strong>.
27+
A new image is fetched every 15 seconds (after refreshing the page) and then served from the cache for that duration.
28+
</Alert>
29+
30+
<Image
31+
src={image.urls.raw}
32+
width={width}
33+
height={height}
34+
alt={image.description}
35+
className="rounded shadow mw-100 h-100"
36+
/>
37+
by <Link href={"/users/" + image.user.username}>{image.user.username}</Link>
38+
</div>
39+
);
40+
}

src/app/NavBar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default function NavBar() {
1818
<Nav>
1919
<Nav.Link as={Link} href="/static" active={pathname === "/static"}>Static</Nav.Link>
2020
<Nav.Link as={Link} href="/dynamic" active={pathname === "/dynamic"}>Dynamic</Nav.Link>
21+
<Nav.Link as={Link} href="/isr" active={pathname === "/isr"}>ISR</Nav.Link>
2122
</Nav>
2223
</Navbar.Collapse>
2324
</Container>

0 commit comments

Comments
 (0)