turbine
turbine copied to clipboard
Simple server side rendering
With a way to stringify a component it would be possible to support simple server side rendering.
The API could consist of componentToString
and serveComponent
. The first would turn a component into a string and the second would return a NodeJS compatible endpoint function.
Example.
app.get("/app", serveComponent("index.html", "body", myComponent));
This would offer a really simple way of getting many of the benefits from server-side rendering with very little effort from end-users.
I imagine that we can use something like JSDOM to run the component in NodeJS and pre-generate the DOM.
@trusktr
That would be awesome to do with Turbine. Maybe we can just run turbine stuff in jsdom, and get the output?
Maybe there could be a way to make Turbine output strings instead of actual DOM elements?
If possible I think turning Components into strings directly is best. If this is something that interests you I can put a simple proof of concept together to illustrate how I imagine it can be implemented.
What do you think about the API I show in the post above?
@paldepind I suppose that works. I'm also looking at Vue+Nuxt.js, which abstracts that part away.
They do it very very declaratively. But so do you!! I think the functional-to-HTML approach you have is nice.