News for hackers. Stuff that matters.
Re:Text-only CNN by ascom on Sunday September 10, 2017 @12:09AM (#15210538)
EDIT: As I wrote this, someone deployed a server-side rendered version of the site. Now the site is perfect. :)

This site appears to load ~350 KB of JavaScript, which I think is a bit excessive for a "lite" text-only site. From the sourcemaps, I found a long list of libraries, including:

* react

* redux

* redux-thunk

* react-router

* axios

* base64-js (why not window.atob/btoa?)

* core-js

* fbjs

* react-hot-loader (should not be in a production build)

* ...a bunch of other smaller modules

There's only about 10 KB of non-library application code. Note that I ignore gzip when evaluating this sort of stuff, since that many bytes of code still need to be parsed, no matter how much it compresses.

For the person who made this site, I would replace React with Preact (or Inferno), which should remove most of the bloat. Server side rendering would also be nice for those who don't have JavaScript enabled and would also improve the loading time.

At least it's still better than cnn.com. http://www.webpagetest.org/result/170910_C8_e78305788a19b0fb...

Re:Text-only CNN by heipei on Sunday September 10, 2017 @02:44AM (#15211061)
Almost anything is better than CNN: https://urlscan.io/result/6834c63f-b092-4e4e-b72b-91bd1c1b82... This is on par with other shitty news-websites.

This website contacted 65 IPs in 7 countries across 35 domains to perform 314 HTTP transactions. [...] In total, 4 MB of data was transfered, which is 12 MB uncompressed. It took 2.753 seconds to load this page.

Compare this to the now-SSR cnn.io: https://urlscan.io/result/7d13efac-ffaa-4ac2-a091-8611e39b20... (59kB transfer)

Edit: Someone scanned the lite-version before they switched to SSR: https://urlscan.io/result/2a9690eb-3992-4712-a657-c3be959d51...

Re:Text-only CNN by a012 on Sunday September 10, 2017 @12:21AM (#15210588)
This reveals why I didn't see anything on my phone on first time visiting it. My browser just show a blank page, then seconds later the contents show up.
Re:Text-only CNN by jimktrains2 on Sunday September 10, 2017 @09:35AM (#15212161)
What's worse all the content is sent inline, just not as html :( Why complicate this so much?
Re:Text-only CNN by V99 on Sunday September 10, 2017 @04:13AM (#15211292)
FWIW, base64-js and similar libraries are still needed (though probably not in this case...) because window.btoa() only works on latin1 ASCII strings. Try giving it some arbitrary UTF-8:

btoa("\ud83d\ude0b") -> Uncaught DOMException: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.

(Edit: apparently HN doesn't either; changed to \u...)

Re:Text-only CNN by josteink on Sunday September 10, 2017 @07:26AM (#15211747)
> FWIW, base64-js and similar libraries are still needed

For what? This is a non-interactive text-only website. It shouldn't need anything beside HTML and CSS.

Re:Text-only CNN by eadmund on Sunday September 10, 2017 @08:17AM (#15211890)
You are 100% correct. Honestly, it doesn't need CSS even, although that's nice to have.

I've got NoScript on, and now the pages load perfectly. I think I may return to being a CNN reader now. If only they could figure out how to monetise this.

Re:Text-only CNN by V99 on Sunday September 10, 2017 @11:32AM (#15212621)
For the rest of the sentence... I was clearly referring to the question of why someone would use a library for base64 versus the built-in function. Not getting involved in the anti-js internet pitchfork mob.
Re:Text-only CNN by earenndil on Sunday September 10, 2017 @12:41AM (#15210671)
FWIW the site still looks fine with noscript enabled.
Re:Text-only CNN by jordache on Sunday September 10, 2017 @12:43AM (#15210679)
WTF? why any JS at all for something that's pure content?
Re:Text-only CNN by dom0 on Sunday September 10, 2017 @06:54AM (#15211670)
Because this site is clearly in need of 250 KB surveillance JavaScript.

So even this "plain text" site still transfers ~98 % bloat and just ~2 % content.

Re:Text-only CNN by AndrewCHM on Sunday September 10, 2017 @09:46AM (#15212193)
transfer is different from filesize

its more around 90% JS, 10% content

After the first page load (with scripts cached) its around 87% content (unfortunately they don't seem to be caching CSS)

Re:Text-only CNN by na85 on Sunday September 10, 2017 @01:31AM (#15210823)
History repeats itself. This is just like flash sites back in the 90s.
Re:Text-only CNN by TomMarius on Sunday September 10, 2017 @05:13AM (#15211450)
It has no benefit on the client itself, but in this (server-rendered) case, you can think of it as improved PHP/Ruby/....
Re:Text-only CNN by josteink on Sunday September 10, 2017 @07:27AM (#15211748)
The question wasn't why anyone was using Javascript on the server.

The question was why a pure-text non-interactive website needs any javascript at all.

Re:Text-only CNN by TomMarius on Sunday September 10, 2017 @08:10AM (#15211872)
Because when you're treating React as a templating language, it's easier to let it run on the client side during development and add server rendering later.
Re:Text-only CNN by jimktrains2 on Sunday September 10, 2017 @09:36AM (#15212166)
Seems like it'd be easier to just use the templates already there for the content on the server, instead of building an additional application.
Re:Text-only CNN by jordache on Sunday September 10, 2017 @12:35PM (#15212922)
i don't know react. Can you elaborate what you mean using React as a templating language? Are you saying react can be used sans any business logic and purely for template interpolation?
Re:Text-only CNN by josteink on Sunday September 10, 2017 @03:23PM (#15213825)
Simply put, React lets you do two things:

* Generate a HTML/DOM based on a template and data.

* Lets you efficiently update that DOM based on updates to the data and/or model (this is it's killer feature).

But if you're just going to do the first thing (generate a HTML/DOM), you don't need most of React's feature set, and you certainly don't need to push heavy JS onto the client.

For those cases, a much better approach (for both clients and SEO) is to just pre-render the DOM/HTML server-side and serve that without any need for any javascript client-side (which is what the similarly named module "Preact" does).

Re:Text-only CNN by TomMarius on Sunday September 10, 2017 @04:05PM (#15214059)
Josteink said it excellently, my addition is that React itself is a view library that lets you update DOM easily based on some data, and the data (and the logic behind it) can be and often are completely separated from React components themselves.
Re:Text-only CNN by crabasa on Sunday September 10, 2017 @12:16AM (#15210568)
>> At least it's still better than cnn.com.

That's literally the entire value prop of the website. The author isn't obligated to use your personal list of approved web tools.