ssrwpo / ssr

SSR - Router with SSR for Node & Meteor
https://ssrwpo.github.io/ssr/
MIT License
93 stars 16 forks source link

Avoid useless initialState for static data. #47

Open cbilotta opened 7 years ago

cbilotta commented 7 years ago

On SSR, you sometime have to fill the store with data that has the only purpose of making the rendering of static HTML possible.

For example, if you want to render a static blogpost, you need to load the blogpost into the initial state, and then you basically have duplication of data between the store and the HTML sent to the client.

One solution to this could be to put an HOC around this block of static HTML that would, on mount in the client, take the innerHTML of it's children, and put it in the store, so for future re-renders, the needed data is actually in the store.

On the server, due to the way we walk the tree, we can easily delete this data from the initialStore and avoid sending it to the client.

This way, we could save precious bytes in the initial HTML payload.