TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

React.Js: Achieving 20ms server response time with Server Side Rendering

53 pointsby ateevchopraover 8 years ago

17 comments

btownover 8 years ago
What this article <i>should</i> have linked to: <a href="https:&#x2F;&#x2F;github.com&#x2F;walmartlabs&#x2F;react-ssr-optimization" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;walmartlabs&#x2F;react-ssr-optimization</a><p>&gt; After peeling through the React codebase we discovered React’s mountComponent function. This is where the HTML markup is generated for a component. We knew that if we could intercept React&#x27;s instantiateReactComponent module by using a require() hook we could avoid the need to fork React and inject our optimization. We keep a Least-Recently-Used (LRU) cache that stores the markup of rendered components (replacing the data-reactid appropriately).<p>&gt; We also implemented an enhancement that will templatize the cached rendered markup to allow for more dynamic props. Dynamic props are replaced with template delimiters (i.e. ${ prop_name }) during the react component rendering cycle. The template is them compiled, cached, executed and the markup is handed back to React. For subsequent requests the component&#x27;s render(..) call is short-circuited with an execution of the cached compiled template.
评论 #12728788 未加载
评论 #12732334 未加载
misterbowfingerover 8 years ago
The headline should&#x27;ve been &quot;it takes 150ms to do server-side rendering with React,&quot; not, &quot;hey everyone I can put something in Redis.&quot; I would _not_ take this person&#x27;s advice. There&#x27;s most likely something else really wrong with their code.<p>Also.... 20ms with caching the pages in Redis? That sounds really, really slow. There&#x27;s definitely something else going on.
评论 #12728393 未加载
评论 #12728267 未加载
评论 #12729850 未加载
评论 #12732367 未加载
评论 #12728615 未加载
prashntsover 8 years ago
&gt; For this, we created a small param cache=false. Whenever the url is hit with this URL, the node server makes and API call instead of fetching data from the redis cache. And hence the cache is updated with the newer data.<p>&gt; Whenever you deploy, new chunk hash for js and css files gets generated. This means if you’re storing the whole HTML string in the cache, it’ll become invalid with the deployment. Hence, whenever you deploy, the redis db needs to be flushed completely.<p>These arguments sound like over-engineered &quot;solutions&quot; by somebody who did not do their homework. To speed up your SSR, render components, not the _whole_ page. Vast majority of your page is going to remain constant: the head, navigation, footer. Rendering these components in partials will save you the Redis store by a very, _very_ large margin. Once they start caching hundreds of thousands of HTMLs, the Redis server will start swapping the content from memory to the disk. There, you just defied the whole point of using Redis.<p>Also, your users are _still_ going to see the 810ms latency the first time they access your service. How often do you think they&#x27;ll be reloading right after the page is loaded? And once the cache is invalidated -- which I suppose would happen frequently -- the _visible_ latency is still high.
评论 #12732392 未加载
mgallowaover 8 years ago
I thought I was going to learn how to speed up my SSR, instead I learned about how to hide from my problems by using Redis. I am disappointed.
评论 #12734322 未加载
sciurusover 8 years ago
At the point where you&#x27;re able to cache the exact HTML you&#x27;re returning to the client, it&#x27;s more efficient to do that in front of your node server than behind it. A cache hit can avoid your application completely, which is a real boon for performance and scalability. You can run your own caching http proxy, like varnish, or use a CDN like Fastly.
评论 #12728408 未加载
评论 #12734350 未加载
wmfover 8 years ago
This makes me wonder how many people are using AJAX as an excuse for slow response times. If &gt;500 ms isn&#x27;t acceptable for a full page load then it shouldn&#x27;t be acceptable for an AJAX REST call either. A page showing a spinner instead of content isn&#x27;t any more useful to the user than a blank page.
评论 #12729875 未加载
yazaddaruvalaover 8 years ago
If your HTML is cacheable: You just need to set your HTTP header&#x27;s appropriately.<p>You can also invest in a CDN. Now we have a React.js SSR with 0ms server response time! :)
jeffnappiover 8 years ago
TLDR; Caching improves performance.
schmrzover 8 years ago
I&#x27;m quite interested in learning why the author decided to use React for the user-facing part of the blog in the first place.
评论 #12734363 未加载
merbover 8 years ago
&gt; 150 ms for server side rendering<p>that&#x27;s really really really bad for generating a html (and even sending it to the user).<p>I can achieve the whole damn thing in 20ms or less.<p>&gt; The average response time fell to 20 ms !<p>yep in java&#x2F;go&#x2F;whatever you don&#x27;t need the cache, with it your avg response would drop even further!
评论 #12732664 未加载
petetntover 8 years ago
The title reminded me of react-dom-stream[0] which is accompanied by this great talk[1]. Went back to see if some parts of it landed to the core[2] but it hasn&#x27;t seen any progress as of late. Oh well.<p>[0]: <a href="https:&#x2F;&#x2F;github.com&#x2F;aickin&#x2F;react-dom-stream" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;aickin&#x2F;react-dom-stream</a> [1]: <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=PnpfGy7q96U" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=PnpfGy7q96U</a> [2]: <a href="https:&#x2F;&#x2F;github.com&#x2F;facebook&#x2F;react&#x2F;issues&#x2F;6420" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;facebook&#x2F;react&#x2F;issues&#x2F;6420</a>
benguildover 8 years ago
This article mentions SEO.<p>As far as I know, as long as the content is embedded in JSON&#x2F;JS when the page loads, it&#x27;s fine to then &quot;render&quot; it with JavaScript. It&#x27;s 2016 and Google started crawling JS websites a while ago.<p>However, if you fetch it with AJAX after the page loads, Google won&#x27;t see it because it doesn&#x27;t necessarily follow AJAX calls nor wait around for them to return in 810ms. They&#x27;ll most likely only render the bundled content.<p>You can use the &quot;fetch as Google&quot; tool in Google Webmaster Tools to try this out for yourself.
agnivadeover 8 years ago
Soo .. the whole point of the article was that you used Redis to cache your html response and got an improvement.<p>Umm .. nice work ? I guess ..
petercueover 8 years ago
So... we&#x27;re back to server-side rendering?
评论 #12729842 未加载
评论 #12729967 未加载
ameliusover 8 years ago
Nice, except, I suppose, if you have a system where the HTML ultimately depends on the size of the window.
angry-hackerover 8 years ago
Why on earth react for a blog..?
geggamover 8 years ago
Please tell me all the horrible javascript is going to be rendered server side soon<p>My browser would thank you