wincent / masochist

⛓ Website infrastructure for over-engineers
MIT License
78 stars 26 forks source link

Switch to streaming server rendering #98

Closed wincent closed 6 years ago

wincent commented 7 years ago

Likely to be in React 16, enabled by the Fiber rewrite. This will be cool because with my current implementation I have traded SEO (server rendering → indexability) for speed (server rendering → synchronous and slow).

wincent commented 6 years ago

Some links:

Obviously there are some limitations to how early I can start streaming. In the simplest case, I can start streaming the static parts of the <head> (styles, for example) right away, but there are <meta> tags and <title> that I can't know ahead of time in a lot of cases (ie. they depend on the fetched data, and even on the render result in the case of <title> due to my use of DocumentTitle). Another limiting factor: sometimes we decide to do a redirect as a result of something that happens during rendering. Even so, in the spirit of micro-optimization, probably worth doing.

wincent commented 6 years ago

So I did it, but turns out the wins are pretty small on the main index: might be bigger wins on very large pages. I should also look into whether nginx is buffering the response (or even express) in a way that is hurting us. It is true that we do need to fetch data even before streaming the first bytes, so getting that out of the critical path will help for sure, if it can be done in a non-shitty way.

Before:

blog_ _wincent_com

After:

blog_ _wincent_com
wincent commented 6 years ago

To clarify: by "pretty small", I mean, "undetectable".