kaleidawave / prism

(No longer in development). Experimental compiler for building isomorphic web applications with web components.
MIT License
110 stars 1 forks source link

Progressive server side rendering #25

Open kaleidawave opened 3 years ago

kaleidawave commented 3 years ago

Prism SSR functions will only return once the whole page/content has been string concatenated. This is okay but a technique known as progressive render improves on this process by yielding chunks back that can be written / streamed to the response. Using Transfer-Encoding: chunked in the response header means the client will gradually render in content before the server has ended the response.

These would mean ditching the current template literal approach and instead using yield with a generator function. And there would need to be some figuring out to where to draw the end of chunks while still being correctly parsable by the client.

The other thing is that progressive render is to get content to client before all the data / state has been fully formed on the server rather than to send content before the full concatenation is done. aka progressive render is for dealing with the speed issue of getting data for the view (e.g. accessing and making db requests) rather than the time it takes to do the string concatenation (which is already fast).

This complicates things as rather than sending a fully formed data structure to the render function it requires some sort of partial unresolved state. This can be done is JavaScript with getters, promises and generators but I am unsure of how it would work out in Rust (#19).