joystick icon indicating copy to clipboard operation
joystick copied to clipboard

Add a static option to res.render()

Open rglover opened this issue 3 years ago • 3 comments

If a page has no need for interaction, make it possible to flag it as a static page in res.render() like this:

res.render('ui/pages/index/index.js', {
  layout: 'ui/layouts/app/index.js',
  static: true
});

The idea being that you can just omit scripts during SSR and only return the compiled HTML/CSS. Would be good for any page that doesn't have any DOM events/state/interaction.

rglover avatar Dec 14 '22 21:12 rglover

Closing #283 in favor of this.

rglover avatar Jul 23 '24 21:07 rglover

The note above isn't 100% correct. This should create a built, cached copy of the page at a path like /static in the app. At deployment time, the build would generate these pages as static HTML, CSS, and JavaScript. Then, the res.render() function could check that path relative to the page it was passed. If a file exists, it defaults to that (barring some expiration logic), if not, it generates it and returns the initial build.

rglover avatar Jul 24 '24 22:07 rglover

An alternative option for this is to add a separate method called res.static(). Same idea as above, but it'd be an independent method that could have its own options/perf tuning.

rglover avatar Jan 10 '25 08:01 rglover