r/javascript • • Oct 27 '17

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

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

52 comments sorted by

36

u/edwardmsmith Oct 27 '17

2

u/nivijah Oct 28 '17

Great presentation, thank you

91

u/aventic Oct 27 '17

I dont get why they used React for their landing page? It’s some text and a images plus some links, seem overkill to use a framework for that anyway. Am I missing the point?

87

u/kaikomai Oct 27 '17

They explain why here - https://news.ycombinator.com/item?id=15568305

Looks like their landing page is way more complicated than meets the eye.

79

u/clarle Oct 27 '17

Hey, I wrote this! Happy to answer any questions here too.

16

u/snoop_dolphin Oct 27 '17
  • While A/B testing, what changes made the biggest impact on the conversion rate? (good and bad)

  • How complicated is the machine learning used for A/B testing. How much of an increase did you see from it?

37

u/clarle Oct 27 '17

I can only speak to the engineering side of things, but app performance and load time is very important to us.

You can see some more of our public talks on performance on our engineering blog.

For machine learning, we use a learning technique called explore / exploit. You can learn more about that in our engineering blog post where we talk about using it for boxart selection.

26

u/[deleted] Oct 27 '17

React as web components is very valuable even if there's limited interaction. I've seen codebases reach a critical mass where you have enough react components that it just makes sense to keep going. If you've built 8 react buttons out of necessity, next time you need a button on a landing page, you have them ready to go and are not going to fragment your code.

0

u/[deleted] Oct 27 '17

[deleted]

42

u/p0tent1al Oct 27 '17

This is Netflix we're talking about. Let's be real. Give them the benefit of the doubt. You have no idea why they're using React there.

15

u/u982744 Oct 27 '17

So what if they're Netflix? I remember people years ago assuming when Facebook first became popular that it was a shining example of development excellence when in fact it was a cobbled together piece of shit. These things are popular because they are a great idea or have great content. The first versions are rushed efforts trying to get something out there to make money. The development quality comes iteratively later over time. This is no different for Facebook and Netflix.

11

u/p0tent1al Oct 27 '17

It's a little bit more difficult to do that now as Facebook is creating most of the software we're using these days. And Netflix is an active member in the React community. I'm not saying their immune from criticism but... if you're going to call out Netflix when you don't know what type of problems they're trying to accomplish, you have to make an actual argument. And if you follow the trail and look at Netflix's explanation for why they're using React, it makes 100% sense. So it all goes back to my original argument.

1

u/nobodykr Oct 28 '17

Correction, Facebook is buying all the software and apps we regularly use hehe don’t take me wrong .

-25

u/StuffMaster Oct 27 '17

All I know is that their page gets worse over time.

17

u/p0tent1al Oct 27 '17

You haven't addressed the issue. If you're a company and you have a blazing fast homepage and your company takes in 10,000 every month... and you have the opportunity to quadruple that amount by increasing the size of the page load (doing a/b tests, whatever they're doing)... you'd do it right? (Hint: If you wouldn't, you most likely wouldn't operate a successful company).

Guess what? Reddit is subjectively worse for having that dumb sidebar on the right there, not allowing the page to be responsive, doing all their Reddit.com url redirects. What you have to address, is what exactly they're trying to accomplish, and if it has merit (most of the time this means financially). Netflix is very active in the React community and is one of the big adopters. Not that arguments don't have validity in of themselves, but unless you do React conferences or you're a foremost leader in the community, you can't just be like "Oh it's Netflix, what do they know...". Not only are they using React but they're an extremely successful company.

Again, I'm not saying they're immune from criticism but come on. You can't just be like "oh yeah Netflix is as bad as Comcast and EA". They deserve a little bit more credit.

7

u/XPTranquility Oct 27 '17

Netflix is an industry leader when it comes to online streaming. HBO and cable companies are still trying to catch up to Netflix’s UI. Netflix knows what the fuck is up. Front end development is in a very experimental phases. Lots of new technologies and practices coming about. React being one of those. In software development “don’t knock it til you try it” is a very valid argument.

1

u/ImCerealsGuys Oct 28 '17

HBO go is so slow compared to Netflix, their UI is okay but man it’s slow AF.

4

u/[deleted] Oct 27 '17

I still don't get how a button and a background screen warrants 300kb of javascript. We compress React for our landing pages to 2.5kb of loading effort, plus a couple of bytes for the initial views, while bigger parts are split up and async load in the background. Maybe Netflix has very intense things going on underneath, but i'm scratching my head ...

3

u/tswaters Oct 28 '17

It's quite a bit more than that - https://news.ycombinator.com/item?id=15568305

throw react, redux, react-redux, i18n, logging/thunk/reselect plus anything else they have, maybe react-router and friends in a vendor bundle and 300kb sounds about right, even minified.

and when it comes down to it, they came to the same conclusion - that landing page has an anchor to sign in and the signup flow which is the interactive part - prefect that using xhr and it loads wicked fast while getting high TTI on the actual landing page

1

u/[deleted] Oct 28 '17 edited Oct 28 '17

Makes sense. Though - most of these we use ourselves, and to reach 300kb with them, not sure how that's even possible unless they don't minify. Looking into the bundle report, react (->preact-compat) is at 3kb, react-redux 4kb, react-router 5kb, ... they're all tiny modules. A small logo.png we load is bigger then the entire framework loading effort.

1

u/tswaters Oct 28 '17

I found the 300kb to be reasonable because I've got a personal project that uses all the bells/whistles; SSR routing / chunking / localization / etc... and the vendor directory - anything imported from node_modules - is 330kb.

I've taken a look at the bundle analyzer and I'm not sure where you're getting 3kb for react -- react-dom.min.js in their dist directory is 128kb.... parsed size in my vendor.bundle.js is 111.16kb - that's the lion's share. next biggest is babel-runtime at 25.83, followed by react-router-server 21kb, react-router 18.38, react-intl 17.52.

gzipped, the whole thing can get down to 94kb.

Also, that's react 15.5. I heard 16 is smaller but I haven't gotten around to upgrading the project yet.

1

u/[deleted] Oct 28 '17 edited Oct 28 '17

The 3kb (gzipped) you get when you alias to preact-compat, or a little larger for react-lite (10kb). It's an api compatible layer where some internals have been taken out, like pooled events. We run most of our apps through it in production to save space. There are some other webpack related things we do to keep bundles small, like cracking down on lodash and corejs, splitting up bundles etc.

2

u/Pr3fix Oct 27 '17

Landing and error pages can be used to pre load your actual app bundle so when the user logs in they don’t need any additional wait time.

33

u/AwayIShouldBeThrown Oct 27 '17

https://i.imgur.com/fv0zGe0.png

(sorry I couldn't help myself)

1

u/cyberst0rm Oct 28 '17

missed the no react, pure vanilla

1

u/prozacgod Oct 28 '17

need to go full perl cgi scripts....

24

u/THE_98_Vikes Oct 27 '17

Seems pretty obvious that using vanilla js would be faster than a framework. Am I missing something?

11

u/HighLevelJerk Oct 27 '17

With the major assumption that you can write optimized JS code (which is unfortunately not true for most inexperienced JS developers).

Technically, all frameworks are written (or transpiled to run in) JavaScript, so you could just rewrite the parts of that framework in JS for your own site that you intend to use and it will always be faster.

9

u/jonny_eh Oct 27 '17

Did they never hear of 'defer'? We need more details!

11

u/[deleted] Oct 27 '17

I was more suprised on them "discovering" caching resources with XHR, a "trick" that the community has been using since late 2000 to preload images that you would show in onMouseOver menu :/

5

u/[deleted] Oct 28 '17

Make that early 2000. new Image(url) in header is a pretty old trick.

1

u/sjwking Oct 28 '17

So they didn't use modern feature like http2 push or defer. Why is that info valuable ? Browser compatibility maybe ?

1

u/[deleted] Oct 28 '17

Yes, they said that it gives them ~95% support across all current browsers.

1

u/p0tent1al Oct 27 '17

deferring can be just as bad. It means you have components popping in with the correct data... even if you had loading states, that still isn't a great experience.

6

u/Geldan Oct 27 '17 edited Oct 27 '17

If they are rendered on the server, the components won't "pop" in. Deferring the javascript will make it so the user can't interact with the components as fast, but they will be rendered like any old static page from days if yore.

Edit: since you edited your post I will edit mine too say that the server is perfectly capable of rendering your components with the "correct data." When done properly there will be absolutely no difference in how a page looks before and after react hydrates itself client-side.

1

u/[deleted] Oct 27 '17

They were specifically talking about TTI not TTR (Time To Interactive and Time To Render)

0

u/p0tent1al Oct 27 '17

deferring on the js side is different from server side rendering of react. If you're rendering on the server side, it's not only going to be faster, but the page will be served once it's ready, not served but then the page itself is loading the pieces inside of it.

1

u/Geldan Oct 27 '17

I have no idea what your are taking about, but just so we are on the same page this is what I mean. OP was referring to the "defer" attribute of a script tag: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script

If you render your content on the server side and defer the javascript tag so that it doesn't block rendering you can achieve an extremely fast initial render. If done properly there will be absolutely no "popping in" of content later.

Are you taking about lazy loading?

-1

u/p0tent1al Oct 27 '17 edited Oct 27 '17

Ok... what he's saying, is you defer the javascript so it speeds up the initial page view. The thing you're not grasping, is if you're doing A/B tests in a React architecture and you're conditionally showing components, you have to wait until the javascript is finished loading... deferring isn't going to help you there. The only thing that helps you, is moving the React and A/B tests to the server. Deferring javascript that you rely on to display your view, means you have to wait until the Javascript is ready. If you're mostly controlling views with React then deferring most likely is going to yield no benefits.

{this.props.a_b === 1 ? (
<NetflixSimpleExperience /> : (
<NetflixNewerExperience />)}

See what I mean? How does delaying the loading of any javascript help you here, outside of deferring non React scripts? So when the OP said "haven't they heard about deferring" I fail to understand what benefits that would net you. The takeaway is, is they have to move some of this logic to the server side. Now that they've done that, sure they can defer some things.

0

u/Geldan Oct 27 '17

If you server side render, like they do at Netflix, that conditional will resolve on the server and the initial content will reflect the results. When client-side react hydrates there will be no change because the conditional will resolve exactly the same.

There is absolutely no "popping in" of any type if you utilize renderToString properly. Therefore, if you defer the script, the user sees the content without any future "popping in" just as fast as if a traditionally templated page were being served .

deferring the script stops the download from blocking that initial render so the user sees all of your content faster, but don't cause noticeable jank to the user, so if course it helps.

They don't have to move any logic, they use the exact same logic on the server and client.

1

u/p0tent1al Oct 27 '17

You're not getting what I'm saying. IF you server side render. IF. The inference of them getting rid of React on the client side, is they now are using it on the server. Deferring is something you do in ADDITION to server rendering. And again, if they load the script after the body tag, then I doubt deferring is going to have significant speed benefits.

1

u/turkish_gold Oct 27 '17

That's a poor inference. We use React both on the client and the server.

Server-side rendering has been part of React since the beginning.

As far as I know, Reddit is really the only large company that doesn't make use of it on a public facing site. :-\

→ More replies (5)

1

u/jonny_eh Oct 27 '17

Good point. What's the alternative? Queueing up user actions so that once the deferred app logic loads it then knows what to do?

1

u/spacejack2114 Oct 29 '17

How is server-side performance of React? I suppose server-side renders are cached?

-6

u/lechatsportif Oct 27 '17

This just in - removing unnecessary frameworks results in performance upgrade!