Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

You could take a mixed approach. Server render non-stateful stuff, restrict user state to client-side only. You can then CDN cache the public stuff.


sort by: page size:

Okay....but that's you providing a backbone for the user. Don't you just use a CDN at that point? (One that allows non-cached requests as well.)

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.

server side rendering also points you toward more cacheable content. Things you put on a CDN are faster and way cheaper.

At cost of reducing cache ability though no?

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.


Very understandable for a CDN. You can use page rules to disable caching on various levels (even in the free tier, just with limitations).

I mean your browser basically already does this by utilizing cache-control and expires headers, which all CDN's are going to set

This doesn't seem like an issue. You can store images / other assets on the CDN, and serve the real time stuff from the origin without caching.

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.

This concept is really neat!

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.

You lose the benefit of a CDN though (caching content on a server closer to where each individual user is accessing it)

First, there are people that don't want to use a CDN (don't trust them with censorship), or can't (local network).

But you can cache other things that are not the entire page itself:

- database queries

- user sessions

- api calls

- page fragment

- function memoization

What's more, cache backends have the ability to expire things, which can be helpful for all sort of stuff.


I don't see why they would be more of a hassle. Why would they even care if the HTML is being rendered on demand or pre-rendered and stored?

Regarding cache, I don't agree - having your site cached by the edge nodes of a CDN is quite important nowadays.


You could have CloudFront in front of your application servers, though, and it could be doing passthrough requests for non-cacheable assets.

Not that I'd ever want this, because CloudFront is dog slow compared to other CDNs, but yeah..


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).

Dynamic responses also can be cached in a CDN you know...

This is interesting... Is there some distributed caching server one could use for this, for increased uptime? Basically some CDN.
next

Legal | privacy