3 ms·
It's a cost thing... a lot easier to CDN static HTML files and only make edge calls as necessary. In our Next.js setup, for example, all pages are served stati
by technobabbler 5y ago
It's a cost thing... a lot easier to CDN static HTML files and only make edge calls as necessary.
In our Next.js setup, for example, all pages are served static by default and cached around the world, but every revalidation period (60 seconds or so?), one edge worker will check the data source against the upstream CMS, and rebuild that one page if needed.
That means our max edge worker and API call is 1 per minute, regardless of whether there are 10 visitors or 10 million. The others will just get the cached CDN files.
That makes it a lot more affordable.
If you had infinite budget and could pay for edge functions to re-render the page every visit, with or without caching, then more power to you. But not everyone can afford that.
Edit: Also, a secondary benefit is accessibility. Since most of the content is served as a flat HTML, those with outdated browsers/misconfigured ad blockers/javascript turned off can still see the most important part of the content. Maybe they miss some interactivity, but they can still at least read the gist of the article since that's just HTML.
Depending on your specific edge function configuration (i.e. whether it needs web workers or web sockets or such) some browsers may not load that correctly. Dangerous for that to be the only delivery mechanism. But if your edge function just masquerades as a web server and returns plain old HTTP, that shouldn't be a problem.
- jennings_hunter 5y ago> In our Next.js setup, for example, all pages are served static by default and cached around the world, but every revalidation period (60 seconds or so?), one edge worker will check the data source against the upstream CMS, and rebuild that one page if needed. Are you all using the incremental static regeneration API to accomplish this?
- technobabbler 5y ago> Are you all using the incremental static regeneration API to accomplish this? Yep. It's great, if hackish. A good overview (https://www.smashingmagazine.com/2021/04/incremental-static-regeneration-nextjs/ https://www.smashingmagazine.com/2021/04/incremental-static-...) or Vercel's own docs (https://vercel.com/docs/concepts/next.js/incremental-static-regeneration https://vercel.com/docs/concepts/next.js/incremental-static-...) Vercel aside, I think Cloudflare by itself works similarly if you configure it to "cache everything", including HTML pages, on a revalidation period. I find this a great balance between serverside rendering and static builds. Specifically it allows you to rebuild certain pages as things are created/updated (new or edit blog posts, products, etc.) without having to trigger a full rebuild every single time.