Improve page performance by using renderToStaticNodeStream
#218
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Almost everything on the pages are static, we can get rid of
renderToString
and don't have to include the js files at all. This significantly improve the performance. Below is the lighthouse score comparison running on my macbook pro (2018, 2.7GHz i7, macOS 10.14.6) on pageunpkg.com/lodash/
(Applied slow 4G, 4x CPU slowdown).(The resulting 2 points left could be text compression, which can be solved when served via cloudflare.)
We also use
renderToStaticNodeStream
to stream the result to be able to flush the first bytes to the client more quickly comparing torenderToStaticMarkup
.There are only two places which use client side js I can find. The version selector in the browse page and the stats in the main page.
onChange
handler with a vanilla js one. We can inline the js file directly below it to save the additional request too.useEffect
. We can replace all of that with just inlining the result during SSR. One caveat is that if we want to preserve the 1 hourcache-control
for stats, we have to also change the main pagecache-control
from 4 hours to 1 hour. I think it's okay regarding it's not a page which would get requested frequently. Another advantage would be that we can removelocalStorage
usage too.Regarding what the vision of this project is, it's either a very good idea or a bad one. Either way, for now it looks like a free optimization. Please let me know your thoughts on this 🙂.