Thats what we did a former company. You cache the main page on the edges of a CDN. When logged in, you'll get JSON blob that is also cached on the edges using oauth/jwt header as a dimension for the cache key. JSON blob has the users information like username, name etc and its just filled in. Makes the pages extremely performant since everything is cached on edges and protects your origin servers from load. You could also shove stuff into web storage but private mode for some browsers won't persist the data.
It is cheaper for me to put my react app in front of a cdn, split out my app into an api and front end than for me to have my site be entirely uncacheable.
I can also cache certain endpoints behind the cdn that are mostly invariant for users.
And, the network egress of json is much lesser than the egress of markup.
Can you please explain more? I thought since it is server rendered it would cost more than SSG pages served from CDNs. Can we cache pages until they are changed in a CDN?
The website is public. There's nothing keeping them from having using a CDN or other caching service or, better yet, setting up their own caching servers to handle the load better.
On several of my modern projects, there's not a single piece of static data that can't be cached forever in a CDN. That's because server-side code is not getting really good at managing the initial build of static assets and the delivery of their URL.
I do have one question: how would something like this work when your webpages are being cached or when you're behind a CDN? As far as I can see none of this can work unless all requests hit your web server.
Does anyone know of any solutions that work similarly, but would allow for CDN's and caching? I'm aware that these will probably need JS, but I'm fine with that.
Exactly, you’re incentivized to make your website as static as possible, and I attach standard http cache headers to most of the server rendered stuff so that their responses get cached in Vercel’s CDN, and once again not invoked super often.
It sounds like you're asking for a p2p CDN / caching layer. Having it be auto-generated would be tricky, as it's hard to determine if the page you're seeing is meant to be public or private (e.g. for your eyes only).
reply