This episode covers caching strategies for an Astro site: caching for static and SSR content, CDN integration and cache invalidation, prefetching and resource hints, and network payload and page speed optimization.

After content and authentication are secure, it is time to make sure everything reaches the user as fast as possible. Episode 14 covers caching and request performance: how browsers and CDNs store copies of pages, when a cache must be invalidated, and how to tell the browser which resources will be needed next.
The key to understand: cache is not a saving — cache is speed. The more requests served from cache, the less waiting users experience. For a static Astro site, almost all content can be cached aggressively.
You will learn cache strategies for static and SSR modes, CDN integration, prefetching, and payload optimization.
Static content from npm run build — HTML, CSS, JavaScript, images — can be cached aggressively. Because files are hashed, use a long cache:
Cache-Control: public, max-age=31536000, immutableThe value max-age=31536000, immutable tells the browser not to revalidate the file for a year. Changed filenames automatically force the browser to fetch the new version — safe and fast.
For static HTML pages, set a short cache so content updates spread quickly:
Cache-Control: public, max-age=60, stale-while-revalidate=3600The stale-while-revalidate=3600 directive lets the browser use the old version for up to an hour while fetching the new version in the background — the page always feels fast without waiting for updates.
SSR pages are dynamic, but they can still be cached carefully. Apply Cache-Control in the server response, for example max-age=60 for pages that rarely change per user, or set private for personal content:
---
Astro.response.headers.set(
"Cache-Control",
"public, max-age=60",
);
---The code above sets the Cache-Control header directly from the SSR page. For per-user content, switch to private so it is not cached in a shared CDN.
A CDN stores page copies on servers close to users around the world. On every deployment, the CDN must know which content changed — this is cache invalidation. Modern hosting platforms like Vercel and Netlify automatically mark old files when a new deploy happens. For custom CDNs, use the purge API or re-upload hashed files.
The ideal combination: static HTML cached short, hashed assets cached for a year, and SSR pages cached according to how dynamic they are. Check cache effectiveness through response headers using curl:
curl -sI https://situs-kalian.dev/ | grep -i cache-controlcurl -sI shows the response headers. Verify that Cache-Control matches what you expect after deployment.
Astro provides the @astrojs/prefetch integration that automatically prefetches page links as the user approaches them:
npx astro add prefetchOnce the integration is installed, Astro adds prefetch for all links when the mouse approaches or the screen touches a link — the next page feels instant without manual JavaScript.
For more detailed control, use HTML resource hints:
<link rel="preload" href="/assets/font.woff2" as="font" />
<link rel="preconnect" href="https://fonts.googleapis.com" /><link rel="preconnect" ...> opens an early connection to an external domain, and preload fetches critical assets earlier. Both speed up the time until assets are ready to use.
Every byte not sent is a byte not waited for. Repeat the habits from episodes 7 and 9: minimize JavaScript through partial hydration, optimize images with astro:assets, and clean up unused CSS.
Measure the impact of all these strategies with Core Web Vitals: LCP for main content speed, CLS for layout stability, and INP for interaction responsiveness. Episode 15 will dig deeper into profiling, and episode 22 covers long-term monitoring.
Tip
The combination of prefetch and short caching makes blog-to-blog navigation feel instant — a reading experience that rarely draws speed complaints.
Episode 14 strengthens the network performance layer: cache strategies for static content, HTML, and SSR, CDN integration with proper cache invalidation, prefetching with @astrojs/prefetch and resource hints, and page payload optimization.
The key takeaways:
immutable.stale-while-revalidate.private caching.@astrojs/prefetch makes cross-page navigation feel instant.curl -sI is the quick way to verify cache headers.In the next episode 15, we will cover performance optimization: profiling with browser tools and Lighthouse, reducing the JavaScript payload and minimizing hydration, preloading critical assets, and build-time optimization and incremental builds. Your performance numbers will become the basis for design decisions.