cheatcode / joystick

A full-stack JavaScript framework for building stable, easy-to-maintain apps and websites.
https://cheatcode.co/joystick
Other
209 stars 11 forks source link

Add ability to static render routes on-demand #283

Closed rglover closed 2 months ago

rglover commented 1 year ago

Idea here is to say "when a route is hit, if the static option is set to true, check if there's an existing cached copy." If there is, return that as the response. If not, generate it and then return it as the response.

This would make it so that the first request to a route is "hot" and the rest are pulled from the disk cold. Compelling, because it would allow you to selectively make pages static in the app as opposed to a wholesale static site (as in SSGs).

rglover commented 2 months ago

I think this is best done via res.render() options. That way, we can tie a static build of a page/component to a specific file path. If static: true is set on the res.render() options, we would just default to reading the built copy from disk.

To invalidate a build, it could either be manually deleted from some path (e.g., /static in the root) or there could be a timeout designated by a timestamp.

I built an early version of this a ways back that more-or-less automated cached copies of pages (the intent was to act as a cache, not an SSG replacement). May be some notes in there to pull ideas from.

rglover commented 2 months ago

Closing in favor of #237.