r/programming • • Oct 27 '17

Netflix: Removing client-side React.js improved performance by 50%

https://twitter.com/NetflixUIE/status/923374215041912833
685 Upvotes

89 comments sorted by

211

u/DoListening Oct 27 '17

It only talks about the landing page. The full tweet goes

Removing client-side React.js (but keeping it on the server) resulted in a 50% performance improvement on our landing page

The very next tweet says they still use React on subsequent steps.

103

u/basilect Oct 27 '17

And that's what Google does with Google Maps, for example. First page is rendered server-side, subsequent pages are rendered client-side. A hybrid approach is the fastest, but it requires more work so people either choose one or the other.

23

u/Theemuts Oct 27 '17

Server-side rendering is a pretty common optimization in frontend development, isn't it?

89

u/[deleted] Oct 27 '17

It's funny when thing that was a norm 10 years ago is now "optimization"

20

u/occz Oct 27 '17

Full SSR used to be the norm, now SSR is an optional optimization you can do to make one particular aspect of the user interaction better. In general you do a server-side render once and then do subsequent renders client-side.

24

u/ghostfacedcoder Oct 27 '17

If you care about optimization yes. However, the vast vast majority of web applications I've used/worked on were not even close to Google's level. When you're a 100 person start-up you care far more about adding features and fixing the bugs in your app than you do about shaving a couple seconds off its load time.

And even if performance does become enough of a problem to qualify as a "bug", there are lots of other "low hanging fruit" ways to fix it that don't require rendering in two places. You can use different domains to serve static assets, configure Webpack to bundle things better, do some debugging to find obvious memory leaks, bind event handlers that are the same on lots of elements to a common parent ...

11

u/thekab Oct 27 '17

When you're a 100 person start-up you care far more about adding features and fixing the bugs in your app than you do about shaving a couple seconds off its load time.

Right. However, those features are worthless if the user leaves because it's not performant. I know you're just making up an arbitrary number but two seconds is huge.

The last time I worked for a company with less than 150 employees that was dependent on a public facing site for revenue there's nothing, absolutely nothing aside from maybe the entire site being offline that would be more important than shaving 2 seconds off load times.

11

u/[deleted] Oct 27 '17

2 seconds is quite high, Amazon found that every extra 100ms of latency cost them 1% of sales. Many years ago Google tested going from 10 search results per page to 30 because users wanted more search results per page, well when they did it traffic dropped 20% because it added 0.5 seconds to the loading time.

1

u/thekab Oct 27 '17

That's why you get a fixed rate home loan. You may as well be renting if you get an adjustable rate home loan

Exactly. I think they chose a bad number.

It's really more like "Do I spend 100 hours getting 20ms (we hope) or do we spend it writing this feature sales is sure will generate tons of revenue?" which is never an easy question especially since you never actually know how much you'll actually improve performance.

0

u/[deleted] Oct 27 '17

[deleted]

0

u/[deleted] Oct 27 '17

[deleted]

2

u/bunnyoverkill Oct 27 '17

Indeed! It's just that it's rather surprising that people would google less because it takes half a second more.

2

u/LovecraftInDC Oct 27 '17

I wonder if it's because the half second is an aggregate. Maybe for 60% of people, it added less than a half second, but for the other 40% it added 4/5 seconds.

→ More replies (0)

3

u/ghostfacedcoder Oct 27 '17 edited Oct 27 '17

The last time I worked for a company with less than 150 employees that was dependent on a public facing site for revenue there's nothing, absolutely nothing aside from maybe the entire site being offline that would be more important than shaving 2 seconds off load times.

I don't buy it. Or rather, I don't buy that it's true for all load times/companies. I've worked at nine different Silicon Valley companies, so that's my frame of reference. At any of them if your page takes 30 seconds to load (not something that will happen for the first several years of your company, unless your programmers suck or you're doing crazy things with client-side visualizations or something) then almost nothing is more important than shaving more than 2 seconds. But, it's still not necessarily the most important thing: if your biggest customer is saying "I'm going to switch providers unless I get feature X this quarter" then you still might work on that even with such high load times, because the load time won't necessarily lose your customers, while not having feature X definitely will.

It's worth pointing out here that the people doing the software purchasing are very often not the people actually using the software. So if the page loads slowly it's your customer's rank and file that suffer, but all they can do is complain to their bosses (who might not care at all because your software has feature X, which no competitor does, and so they're willing to make their employees wait).

Now on the other end of the spectrum, if your page loads in 5 seconds, even shaving 0.5 seconds off (let alone 2) is going to take a lot of effot. Why on earth would you spend that effort on something that won't help your business (other than making the people who don't actually make the purchasing decision ever so slightly happier) when you can add features and fix bugs which actually affect your bottom line?

In fantasy gumdrop land you have limitless time and resources to make your app load in 0.5 seconds AND have every feature your customers want WITH zero bugs ... but real companies in the real world have to prioritize for what actually helps the business, and in my experience most of the time (ie. not for Google and Netflix) having their employees shave seconds off the load time simply doesn't do that as well as having them fix bugs or add features.

2

u/thekab Oct 27 '17 edited Oct 27 '17

I don't buy it. Or rather, I don't buy that it's true for all load times/companies.

You don't buy my anecdote about a single company?

Ok then.

In fantasy gumdrop land you have limitless time and resources to make your app load in 0.5 seconds AND have every feature your customers want WITH zero bugs ... but real companies in the real world have to prioritize for what actually helps the business, and in my experience most of the time (ie. not for Google and Netflixhaving their employees shave seconds off the load time simply doesn't do that as well as having them fix bugs or add features.

Yeah it's almost as if someone implied that no company under Google level cares about 2 seconds of performance compared to an unspecified feature and I gave a single example of a small company where those 2 seconds would have been prioritized above virtually everything else.

It's almost as if you took that and made up a whole bunch of shit I didn't say, agreed with my point and then acted as if you were somehow countering it.

1

u/ghostfacedcoder Oct 27 '17 edited Oct 27 '17

Reading comprehension on forum posts can be challenging, but I mean, you quoted me saying I don't buy it ... for all load times/companies. Most people would understand that to mean it may well be true for your particular company, or for others, but in general I don't think it's true. It does not mean I "don't buy [your] anecdote", nor does it mean that I said "no company under Google level cares about 2 seconds of performance".

What I did do was make a generalization about of the priority of spending resources on performance vs. spending them on other things:

the vast vast majority of web applications I've used/worked on were not even close to Google's level. When you're a 100 person start-up you care far more about adding features and fixing the bugs in your app than you do about shaving a couple seconds off its load time.

(and I then went on to address the cases that didn't meet my generalization: "And even if performance ...")

I stand by that claim, as a general statement, just not for all companies (and especially not for big consumer-facing ones like Google).

1

u/thekab Oct 27 '17

hat means it may well be true for your particular company, or for others, but in general (and not for giant consumer-facing companies, as I've already clarified) I don't think it's true.

So you wrote three paragraphs agreeing with me while acting as if it was a counter point.

1

u/ghostfacedcoder Oct 27 '17 edited Oct 27 '17

Is having a conversation on Reddit a problem now? Should I only write one paragraph posts of direct responses to exact statements made in the previous post, and nothing else (and never agree with anyone who posts)?

I don't get where your hostility is coming from to be honest. I'm trying to make some practical statements based on my decade-plus experience in the industry, and you're acting like I've claimed performance never matters, and kicked your dog to boot.

→ More replies (0)

1

u/pdpi Oct 27 '17

However, those features are worthless if the user leaves because it's not performant.

And performance is worthless if the user leaves because the product doesn't actually have the features they need.

The trick is, of course, finding the goldilocks point in between. Where on the server-side/client-side rendering spectrum you should be is a non-trivial question.

4

u/eddiemoya Oct 27 '17

I've always explained this by pointing out that a blank page that does nothing would be blazing fast.

2

u/thekab Oct 27 '17

And performance is worthless if the user leaves because the product doesn't actually have the features they need. The trick is, of course, finding the goldilocks point in between. Where on the server-side/client-side rendering spectrum you should be is a non-trivial question.

Absolutely. Part of the trick is identifying value. How important is 10ms to your customers? And more specifically which 10ms? 10ms off the front page is very different than 10ms off a page that is rarely used.

1

u/mywan Oct 27 '17

For me on my crappy machine I would happily deal with an extra 30 seconds of load time for things like Netflix if the client side scripts didn't bog my machine down so bad the video would constantly chop out, and sometimes even force me to do a reboot to get my computer responsive again.

1

u/CanYouSaySacrifice Oct 27 '17

Performance is a feature? Or is that not the case?

11

u/Kuuichi Oct 27 '17

I think he means for most software companies, performance is usually on the latter end of priorities because web frameworks perform well enough out of the box

(Not suggesting that performance is unimportant)

1

u/ghostfacedcoder Oct 27 '17 edited Oct 27 '17

Call it a feature if you want: there are always millions of features you'd like to add to your product. The problem is, we live in a world with limited resources, which means we have to prioritize.

Personally I see it as a specturm. Just to make up some example numbers, if your site takes 30 seconds to load, you have a major bug that can cause you to lose customers. If it takes 15 seconds to load you have a minor bug: it might annoy users but no one is going to stop using the site because of it. If it takes 10 seconds that's a feature of "loads a little faster than it needs to to keep the users from leaving", and if it takes 5 seconds it's another feature, "slightly more convenient for users".

When its a major bug you absolutely need to fix it ... but if your programmers are even half-way competent it will take quite awhile for your app to get that slow. The minor bug you may want to fix, but probably less than many other bugs (eg. ones that might actually make a customer leave). And as for the performance "features"? Well which would you rather do: make your users a little happier in a way that doesn't matter much to your business, or add another feature which will actually get you new business or keeps a customer from leaving?

9

u/elprophet Oct 27 '17

It depends on what exactly you mean by common. Server Side rendering is pretty common, yes, but adding "Optimization" implies improvement over something else. If it's just "server side rendering", you don't improve over having to render everything on the server, just sending static data to the client (costly in both server time and bandwidth).

On the other hand, you can render nothing server side, and see that browser are just more than fast enough to render complex web applications, so that the only bandwidth is the critical data (aka the part that must live on the server), but then you see your first page load ends up taking a very long time (load HTML; load CSS & JS; parse & evaluate JS; render).

So we're seeing this hybrid approach where the landing page (the very first page) gets rendered server side and then everything else gets built on the client side. But if users can land anywhere, you don't have a landing page, just a happenstance first page.

To get really good latency on that first page you visit, we want to render it server-side and just send it ready to go. But now, we need to implement our entire application twice! Once to render it completely server side, and a second time to render it completely client side. Adding in Android and iOS development, we need to implement our entire UI 4 times! 4x budget, 4x the bugs, 4x the developer communication! That's certainly uncommon to have an organization that has the resources to do so.

This is why we're seeing frameworks try to be "isomorphic"1 where they can run anywhere & generate the same code. So you write your application's render layer once in JavaScript with React Native or Angular's platform-[browser,server,etc] implementations that can meet all these use cases.

That said, none of them are battle-tested at the scale of deployments to prove they work. They have much promise; check back in 3 years to see if they've delivered ;)

1 are we still using that buzzword? I haven't seen it in awhile, but frameworks are still trying to do that thing

1

u/squishles Oct 27 '17 edited Oct 27 '17

there's a tradeoff, it fucks with caching services depending on what the content is.

A registration page will be reasonably similar for each user so it's fine, but if you're looking at a page of per user customized movie suggestions or something that wouldn't work out as well.

3

u/rootyb Oct 27 '17 edited Oct 27 '17

Fastboot is making this a lot easier for developers. Renders dynamic pages/apps server-side, and serves that static HTML to the user, then once it's loaded, it starts transferring javascript to make everything dynamic.

/edit: I should clarify: Ember-fastboot is what I'm referring to.

1

u/jjdonald Oct 27 '17

Yeah, using a heavy weight framework on the landing page is kind of crazy TBH. You're basically wasting a ton of time, bandwidth, and cpu serving your whole framework to bots and accidental click throughs.

0

u/[deleted] Oct 27 '17

[deleted]

2

u/tme321 Oct 27 '17

do basic work that doesn't involve an SPA in vanilla JS and then load in React when you actually need it

That's not even what they are doing. They are using react on the server to render the landing page. Then they serve that result to the user. So it's still react it's just running on the server instead of the client for the initial page load.

1

u/eyeofatigress Oct 27 '17

I was wondering the same.. how would they bridge the gap of user trying to interact before React is fully initialized?

0

u/[deleted] Oct 27 '17

[deleted]

3

u/clarle Oct 27 '17

Yep, the landing page itself has very little interaction (one button, the contextual modules at the bottom).

It's the reason we want to load it as fast as possible, and then pre-fetch the rest of the signup flow (a single page React / Redux app) to load while the user is still on it.

That said, the signup flow has arguably more UI complexity than the member interface. We have a lot more dynamic forms and user input compared to the member UI.

You only see the tip of the iceberg when you sign up the first time, but there's a huge number of UI flows when signing up for Netflix. :)

161

u/clarle Oct 27 '17 edited Oct 27 '17

Hey, I work on the team at Netflix that gave the talk on React in the signup flow in the tweet.

We still love React and are using it everywhere else - it's only been removed client-side from the landing page, where we're optimizing it for initial load. It's still being rendered using React on the server.

The full talks are available here if people want to watch them:

https://www.youtube.com/watch?v=V8oTJ8OZ5S0&t=11m30s

Thought I'd also provide some more context on some common questions that people have asked.

Why are you using React to render a landing page instead of static HTML?

The Netflix landing page is a lot more dynamic than most people think it is.

It's our most heavily A/B-tested page in the signup flow, with even some machine learning models being used to customize the messaging and imagery that you get depending on location, whether or not you were a previous Netflix member, device type, and a lot more. Even beyond that, Netflix supports almost 200 countries now, and there's a different combination of localization, legal challenges, and value messaging for each one. We end up sharing a lot of the logic and UI for these A/B testing and localization challenges throughout the signup flow, mainly through React components.

The example I always love to give is the <TermsOfUse/> component that we have, which to a Netflix customer signing up is literally one or two checkboxes on the UI, but has some of the most complicated logic in the codebase due to the vast number of countries and user states we support. Because of all this, it's more valuable for us to share these common React components across the entire signup process, both the landing page and the rest of the flow, which is a single-page React and Redux application.

We've seen a lot of conversion value though in improving the performance of the landing page, especially in countries with slower connections, but we don't also want to re-duplicate a lot of the shared UI logic that we have.

The tradeoff that we decided to make is to server-render the landing page using React, but also pre-fetching React / Redux / the code for the rest of the signup flow while on it. This optimizes first load performance, but also optimizes the time to load for the rest of the signup flow, which has a much larger JS bundle size to download since it's a single-page app.

What's the performance metric that's being used?

It's TTI (Time to Interactive), when the user can fully interact with the page. This is different than TTR (Time to Render) for us, when the user can fully view the page. There's more information in the talk about the differences.

Why not Service Workers or some other pre-loading / caching mechanism?

We have been experimenting with it, but it's mainly the lack of some browser support - Safari is the main one. Generally the Netflix signup flow needs to have more legacy browser support than the Netflix member experience. Lots of people sign up on a pretty old browser, but only ever watch Netflix on the native mobile apps or a TV device.

Feel free to comment here or tweet at Tony Edwards or myself if there's any other questions that we can help answer.

Though from a lot of experience, 140 characters isn't always enough to provide enough context for JavaScript framework discussions. ;)

If these sort of performance and UI challenges seem interesting to you, our team is also hiring for UI engineers and an engineering manager!

Cheers!

4

u/digitallimit Oct 27 '17

Thanks for the clarifications! The title freaked me out at first, but this reasoning I can follow.

2

u/[deleted] Oct 27 '17

it's mainly the lack of some browser support - Safari is the main one.

stupid sexy IE

1

u/crooks5001 Oct 27 '17

This needs to be higher, to the top with you!

-2

u/Drifts Oct 27 '17

Thanks for the explanation!

Quick question that may or may not be related: Any time I rewind by a small amount of time (approximately 10 seconds or more), the stream loads and gets stuck at 99% for anywhere between 15 seconds to sometimes up to a minute (!!). (I have a super fast connection). Is this related? Or some other issue?

23

u/KManRules1331 Oct 27 '17

I mean, isn't this the point of React though? You're supposed to pay a loading cost up front to reduce loading costs as the user uses the application. Of course the time to interaction of a fresh React page is going to be slower than a static web page with a little javascript, but the purpose of the framework is to reduce loading times of moving to subsequent pages in the application.

2

u/manys Oct 27 '17

I'm not sure what point you're trying to make, is it that nobody else knows how react works?

1

u/KManRules1331 Oct 27 '17

I'm just saying this for those who are writing off frameworks like this for vanilla js. If you only measure a framework by one of it's downsides and write it off as such, you're missing out of the benefits that it provides. I realize Netflix is doing a "hybrid" solution where they attach the event listeners and interaction before they fetch all of React, but for those who are writing off React as just another bulky framework to load aren't seeing the forest for the trees.

1

u/manys Oct 29 '17

for those who are writing off React as just another bulky framework

How many uses of React do you think are overprovisioned? Do you think this might have something to do with reacting to the platform spread its use implies?

That is, if it's common in an industry to use something where it's not really necessary, can you blame people for being conservative about recommending it?

2

u/occz Oct 27 '17

It's one of many things you'd want React for. In this particular case they are trying to optimize for one very specific metric though - get the signup page ready for the user to use as soon as possible, presumably so that they dont lose user interest or something similar.

Once they meet that goal they can load react after that if necessary for the page.

16

u/vcarl Oct 27 '17

Clickbait headline. Another phrasing could be "Reducing JS bundle size reduced time-to-interactive on the logged-out homepage by 50%" but that's not the kind of thing that grabs your attention.

In the talk, he mentions that they're still using React to render on the server and they lazy-load the JS bundle after initial load, so they're still using React. Because of Netflix's massive scale and because they want to have the best possible experience for low performance, low bandwidth environments for their marketing homepage, microoptimizations like shaving a few hundred ms off TTI matter. If you use this as an argument against using React, you've read the headline but not seen the content.

2

u/190n Oct 27 '17

Something written in JavaScript is bad

I smell KARMA!

1

u/kT_Madlife Oct 27 '17

Has anyone used Airbnb’s hypernova for server side rendering? If so how is it?

1

u/cadaci Oct 27 '17

Well a landing page can be cache so yeah removing react that needs to load a library makes sense.

1

u/[deleted] Oct 27 '17

react devs on suicide watch

-17

u/eggn00dles Oct 27 '17

every 6 months a whole new abstraction of javascript come out for what gain? a 50% performance reduction apparently.

im convinced the majority of people who love frameworks do so out of job insecurity. you're inherently valuable if you can spout the trendiest things in JS. you're irreplaceable if you master the convoluted insanity and forced complexity these frameworks introduce.

30

u/n8n8baby Oct 27 '17

Trying to do anything of any complexity with vanilla JS is even more insane than learning a framework. These frameworks were generally written to solve real problems of scale. Granted, some people use heavier frameworks than they should, but writing a large web application in vanilla or JQuery is just foolish.

7

u/venuswasaflytrap Oct 27 '17

I'm currently supporting a home-spun jquery based nightmare. I would happily have some framework based clunkiness instead

2

u/eggn00dles Oct 27 '17

es6 has made it a lot easier to compose well written organized modular code. web components promises to offer many of the things frameworks do now.

i think you could handle anything outside of FB, Netflix, etc... with polymer and es6

3

u/more_oil Oct 27 '17

with polymer

Yes, another databinding library

1

u/PaintItPurple Oct 27 '17

How confident are you that Polymer would give any speedup once you've written enough code for feature parity? Because I don't feel very sure of that at all, and suspect it might actually make things slower, and I also suspect it would lead to more code and less nice code on my part.

1

u/n8n8baby Oct 27 '17

Web components promise to, but don’t actually exist yet. Using a framework gets you closer to that now, and they are generally all targeting the spec, which will make migration reasonably easy when they are finally born.

Netflix is actually not a great example. It does not have a lot of user interaction. There are tons of potential web apps much more complex in that regard, which is what frameworks are good for.

1

u/TimvdLippe Oct 27 '17

Web components are natively supported in both Safari and Chrome stable. 1+ Billion devices that do not require polyfills.

1

u/n8n8baby Oct 27 '17 edited Oct 29 '17

a) Safari doesn't support shadow DOM, which is a foundational requirement for proper web components. *edit: I was wrong here. There was a previous version of Shadow DOM that was only supported in Chrome.

b) Even new software, being developed right now, still needs to support Edge, Firefox, and, if you are business-facing, IE11.

1

u/TimvdLippe Oct 29 '17

a) Safari supports shadow DOM v1 (http://caniuse.com/#feat=shadowdomv1). v0 was only ever implemented in Chrome

b) That is a valid concern. For Firefox it is under development, IE under consideration. Hopefully they are caught up soon :)

1

u/n8n8baby Oct 29 '17

You’re correct on A. My mistake :)

9

u/andrewingram Oct 27 '17

Are you really convinced of this, or is it just fun to imagine that it's the case?

Every developer i've worked with, whilst excited about shiny new tech, only adopts it when it solves a problem they're having.

2

u/andrewingram Oct 27 '17

I'd like to add that when i've seen people adopt the wrong tech, it's down to inexperience, or rather not understanding the wider picture of problems that need to be solved. This means that they tend to "unsolve" a load of hidden problems when they switch to the new shiny.

3

u/absurdlyastute Oct 27 '17

It's too expensive and time consuming to keep implementing tech. I'm convinced this is a contrived scenerio as well.

3

u/againstmethod Oct 27 '17

Sorry but components bound to a nice unified state representation is not an invented benefit. React and redux are valuable.

1

u/absurdlyastute Oct 27 '17

Being able to search and find a solution to an issue online is probably the greatest part of adopting a popular framework. Netflix will likely have less than a handful people that own the knowledge to their tech stack. That's very unproductive.

1

u/boneheaddigger Oct 27 '17

You're right. Let's just do away with frameworks and reinvent the wheel on every project. We'll just get the co-op to whip something up over the weekend. I mean, how hard could it be...its all just typing anyways...

1

u/freebit Oct 27 '17

Let's just do away with frameworks and reinvent the wheel on every project.

Please stop attacking a Straw Man.

Here is how attacking a Straw Man works:

  1. Person 1 asserts proposition X.

  2. Person 2 argues against a superficially similar proposition Y, falsely, as if an argument against Y were an argument against X.

"Let's...reinvent the wheel on every project." --Said No Sane Person Ever

2

u/eggn00dles Oct 27 '17

Do you really think the way the angular 2 beta was handled was smooth? Right now you have the internet diluted with solutions and code blocks that don't actually work because of the constant breaking changes.

You have tons of people invested in angularJS but instead of evolve that more sensibly it's a complete bottom to top rewrite. People spent lots of time learning that and then they burned them when the carpet is pulled out from under them.

It's not unreasonable to desire some stability and sensibility in adopting new methodologies. Also a more controlled beta would have helped tremendously.

2

u/boneheaddigger Oct 27 '17

I assume that response was for me...

Look, I just made a joke. But if you really want to get into it...I really don't care about angular beta 2. Way WAY too new for my line of work. But we do use React and NodeJS, because instead of handwriting our own framework like we use to do, we pick something that has most of the functionality that we'd be writing anyways. It's all a trade off...we get projects up and running faster, at the cost of using someone else's code base.

Recreating all of that ourselves, while offering exact requirements matching and allowing us to fully control the code base, would make projects take longer and simple deliver us back into the same position...eventually we'd just create most components once and reuse them. Essentially, we'd create our own proprietary framework that is kinda sorta supported when devs have time, which they never have the time.

Frameworks aren't about creating job security. They actually make it easier to just pull someone off the street and have them start developing. "Know Angular/React/NodeJS? Great! Read through our custom code. We'll get you started on a project next week when you're ready..." vs "Know JavaScript? Great! Start reading through this code, get a really good feel for how everything works, ask this senior dev (who we pay a fortune for since we can't afford to lose all that tribal knowledge) any questions you have, and when you're done in 2 months we'll get you started on a project...".

If you're basing your project on the ability to just move to the next version of a framework with no problems, you're gonna have a bad time. If you're basing your project on a custom framework that you're expecting to be perfect out of the gate and never have to be rewritten, you're gonna have a bad time. If your basing your project on a beta using code snippets found on the internet, you gonna have a really REALLY bad time.

So before you start any project, you need to decide whether you want to use an old reliable well tested framework that's hard to migrate off of, a proprietary framework that won't be nearly as well tested and nearly impossible to migrate off of, or a bleeding edge framework that is barely tested but will probably be supported longer than the old well tested version. If you have another choice, I'd love to hear about it.

1

u/n8n8baby Oct 28 '17

Just because Angular 2 was a botch job doesn’t mean frameworks are bad. Ember handles upgrades fairly reasonably, even if there are a few bugs that slip in from time to time.

1

u/boneheaddigger Oct 27 '17

It's not a straw man. He was arguing that frameworks were a bad thing due to what he says is forced complexity. I just made a joke about it.

Seriously, not everything is an argument waiting to happen. Sometimes a cigar really is a cigar.

0

u/[deleted] Oct 27 '17

[deleted]

58

u/thecollegestudent Oct 27 '17

Nope. Static web page where we don't need to load some giant framework? Makes sense to delay loading it until later.

0

u/reactnativecoach Oct 27 '17

They switched to server side rendering React

22

u/Nimelrian Oct 27 '17

Then you haven't listened to the talk...

They have been using universal rendering before as well, but now they don't include the whole React bundle where it's not needed (as on the landing page). It still gets prefetched for the other pages once you're on the page though.

0

u/[deleted] Oct 27 '17

[deleted]

1

u/freebit Oct 27 '17

Fucking JavaScript is a cancer to this world.

"Fucking JavaScript is a cancer to eating this world." FTFY :)

3

u/atomic1fire Oct 27 '17

Eh, I just assume that developers use Javascript because it's the lowest possible target between both servers and browser, which means there's parity there that you wouldn't get with PHP or some other language. You could realistically build the frontend and backend together using the same code.

As it's the lowest possible target, there's a lot of development and as a result also probably a lot of subpar projects and tradeoffs.

I think it's neat because of what people can build with it, but I can understand if people think it's inefficient because people are using it for anything and everything.

2

u/jayxeus Oct 27 '17

it's not cancer, just susceptible to it, like PHP

5

u/[deleted] Oct 27 '17

clown

0

u/[deleted] Oct 27 '17

[deleted]

1

u/[deleted] Oct 27 '17

gayclown?

7

u/[deleted] Oct 27 '17

[removed] — view removed comment

17

u/Nimelrian Oct 27 '17

The server renders the initial HTML using React and sends that to the client. From there, the client (can) "rehydrate" the pre-rendered DOM using React, which basically hooks into the already existing DOM tree. This saves time / reduces perceived wait time on the initial render, since you don't have to request the model data necessary for rendering.

So instead of doing:

  1. Request page from server

  2. Server sends barebone HTML file with React app bundle reference

  3. Client requests React app bundle

  4. Server sends app bundle

  5. App needs data for first render

  6. Client requests data from server

  7. Server gathers the data and sends it to client

  8. Client finally renders (Content ready + interactive)

(You can skip steps 5 - 7 if you send the initial data inside the HTML, e.g. as a data-attribute)

You do:

  1. Request page from server

  2. Server gathers data, renders it using React, sends the complete HTML with React app bundle reference

  3. Client requests React app bundle, but already shows the complete, information containing DOM (Content ready)

  4. Server sends app bundle

  5. App hooks into existing DOM (Interactive)

2

u/Kenya151 Oct 27 '17

Great comment, thank you.

6

u/karlshea Oct 27 '17

Pre-renders the HTML using the same code as front-end.

5

u/dschooh Oct 27 '17

The HTML of a client-side React application is just a JavaScript include. The script executes and builds the DOM for your app in your browser. Since Node can execute JavaScript server-side you can use your existing React code-base and send the initial DOM via HTML to your browser. Subsequent user interaction can then be handled via usual client-side React.

Advantages: Fast initialization, search-engine friendly front pages, no changes to code base.

3

u/i_spot_ads Oct 27 '17

If it’s the same thing as Angular Universal (which it probably is) when a user makes a request to a url, what they do is emulate a browser on the server, render the html with react on the server, send html to the user (without react), then send the js bundle (with react) which injects itself to the html and transitions to client rendering, that way user can interact with the interface faster because he doesn’t have to wait for the js bundle to download and render the html.

This shit it pretty difficult to implement and maintain, most of the time it’s not even worth it.

2

u/occz Oct 27 '17

Given some data it generates some HTML. I guess the biggest difference between client-side and server-side react is that the data does not change server-side (on a per-request basis, you can of course change the data between different requests), you only render it once and then you're done.