As an idea, we are floating around the option of introducing Edge Side Rendering (ESR) on Cloudflare Workers.
What if we want the benefits of SSR, without needing the NodeJS runtime & the associated CPU usage server side?
Cloudflare Workers provides a JavaScript runtime that proxies requests to an origin, while allowing requests and HTML DOM to be modified before being returned to the client - this means it should be possible to:
Fetch a response from the origin that is configured for CSR
Parse & inspect the returned HTML DOM to pull out the <div id="app" data-page=" data.
Run ReactDOMServer.renderToString, ideally using a ESR specific JS bundle containing the relevant jsx data.
Re-write the results into the HTML & return the response to the client, caching as necessary.
Client would get HTML to match a page generated by SSR, and can hydrate to become interactive.
The main challenge I foresee at the moment is the need for an ESR specific bundle to be loaded by the worker, so it can proxy any application running InertiaJS and doesn't need to be specifically deployed with the application data - it'll request the JS bundle with the jsx data, as a client would to perform CSR.
I'm not asking for this to be implemented for us - if we go ahead with the idea, I'll be happy to take it towards a proof-of-concept - however, what is the community appetite like for something like this?
Is it something anyone else would find useful? And/or, would you consider accepting it upstream?
As an idea, we are floating around the option of introducing Edge Side Rendering (ESR) on Cloudflare Workers.
What if we want the benefits of SSR, without needing the NodeJS runtime & the associated CPU usage server side?
Cloudflare Workers provides a JavaScript runtime that proxies requests to an origin, while allowing requests and HTML DOM to be modified before being returned to the client - this means it should be possible to:
<div id="app" data-page="
data.ReactDOMServer.renderToString
, ideally using a ESR specific JS bundle containing the relevantjsx
data.The main challenge I foresee at the moment is the need for an ESR specific bundle to be loaded by the worker, so it can proxy any application running InertiaJS and doesn't need to be specifically deployed with the application data - it'll request the JS bundle with the
jsx
data, as a client would to perform CSR.I'm not asking for this to be implemented for us - if we go ahead with the idea, I'll be happy to take it towards a proof-of-concept - however, what is the community appetite like for something like this?
Is it something anyone else would find useful? And/or, would you consider accepting it upstream?
As an example architecture:
As opposed to either CSR:
Or traditional SSR: