News for hackers. Stuff that matters.
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by exabrial on Monday May 29, 2023 @10:12AM (#36114188)
The better question is: Why use Javascript at all for a static website?
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by janpio on Monday May 29, 2023 @10:16AM (#36114221)
The article mentions the functionality that the Javascript is used for: Expanding and collapsing sections, adding the media viewer on thumbnails shown in the page. Both seems like reasonable use cases for interactivity that is (better) achieved using Javascript.
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by rickstanley on Monday May 29, 2023 @10:23AM (#36114292)
CSS has come a long way, I would expect that these things would be ease to achieve with just CSS and HTML, for instance: media viewer -> dialog (I remember this being a HTML thing), collapsing sections -> details/summary (?)

But I guess it's not there yet.

Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by ajkjk on Monday May 29, 2023 @10:43AM (#36114486)
There is always going to be a user interaction that is sufficiently complex as to require JS. Arbitrarily limiting to just CSS severely limits what you can do.
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by onion2k on Monday May 29, 2023 @11:12AM (#36114753)
It's not arbitrary though. It's a choice to save bandwidth shipping unnecessary javascript rather than making it easier to develop the website. At the scale of Wikipedia that isn't unreasonable.
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by ajkjk on Monday May 29, 2023 @12:16PM (#36115327)
It's not unnecessary if the feature is something you want?

There's this pattern on HN: people value a feature as having 0 utility and then become annoyed that someone has paid time/performance/money for them. Well duh, if you discount the value of something to 0, it will always be a bad idea. But you're never going to understand why people are paying for it if you write off their values.

At my last job there were countless pieces of UX to make things smoother, more responsive, better controlled by keyboard or voice reader, etc.. that required JS. It was not possible to make our site as good as possible with CSS, and it certainly wasn't worth the tradeoffs of loading a big faster (not that it couldn't have had it's loading time improved--just, cutting JS was a nonstarter).

Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by onion2k on Monday May 29, 2023 @01:17PM (#36115897)
It's not unnecessary if the feature is something you want?

The js is unnecessary if you can achieve the same result with plain css.

Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by ajkjk on Monday May 29, 2023 @03:29PM (#36117130)
And you often can't.
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by spartanatreyu on Monday May 29, 2023 @07:42PM (#36119450)
In my experience, most people just aren't aware of what CSS is capable of.

But to play devil's advocate: just because you can, doesn't mean you should.

Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by TheAngush on Monday May 29, 2023 @05:53PM (#36118550)
If you replace JavaScript with CSS you aren't saving bandwidth; you're trading it.

In many scenarios I'd argue CSS would require more bandwidth. It can get quite verbose.

Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by uoaei on Monday May 29, 2023 @11:04AM (#36114676)
Fairly certain that's literally the point of simplifying interfaces. Do what you need with what you have. Don't try to shove a racehorse into a VW Beetle.
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by blowski on Monday May 29, 2023 @01:08PM (#36115801)
As the old saying goes “simple as possible but no simpler”. There are likely some uses of JavaScript that make the UI simpler.
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by znpy on Monday May 29, 2023 @10:54AM (#36114585)
My guess is that it’s going to be a tradeoff between functionality and compatibility.

Wikipedia is consulted every day by a lot of people, i guess that a large number of those people are running older browsers.

Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by starkparker on Monday May 29, 2023 @11:02AM (#36114659)
Mediawiki itself is built to support 10-year old phones (which is why the Moto G makes an appearance in the post - it's the official low-end Android benchmark) and older desktop operating systems. https://www.mediawiki.org/wiki/Compatibility#Browsers
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by tommy_axle on Monday May 29, 2023 @04:01PM (#36117476)
Makes sense since the Moto G is also what Lighthouse and a lot of tools driven by it use. So PageSpeed Insights (pagespeed.web.dev), the Lighthouse developer in Chrome tab and even external services like https://totalwebtool.com all generally evaluate mobile performance using it to simulate a slower experience.
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by pier25 on Monday May 29, 2023 @03:36PM (#36117197)
> media viewer -> dialog

<dialog> has only been available in Safari for about a year.

https://caniuse.com/dialog

Wikpedia is one of the most popular sites on the internet. It needs to be as compatible as possible so that means using JS.

Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by manquer on Monday May 29, 2023 @04:06PM (#36117535)
You should be able to detect user agent and determine capability and send the poly-fills for backward compatibility ?
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by pier25 on Monday May 29, 2023 @05:01PM (#36118077)
Sure, there are many different ways to tackle this.
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by ryan_lane on Monday May 29, 2023 @09:23PM (#36120155)
Then you'd need to shard your cache on user agent, which would lead to considerably worse performance for everyone.
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by manquer on Tuesday May 30, 2023 @05:03PM (#36130768)
Surely at the scale of Wikipedia that wouldn’t be a factor ?

considering the dominance of few browsers (chrome , safari on iOS) will most users notice any difference? The first one (with that UA) to the site with a new build will have they cache key warmed up ?

Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by ryan_lane on Tuesday May 30, 2023 @08:23PM (#36133010)
User-agent is way more granular than chrome, safari, firefox, etc. It's not a great shard key.
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by paulddraper on Tuesday May 30, 2023 @12:03AM (#36121006)
And hurt your caching....

All to get rid of a tiny bit of JS.

Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by manquer on Tuesday May 30, 2023 @05:05PM (#36130789)
All this to support older browsers and get rid of all JavaScript where you can .

Plenty of sites aspire to be JS free for a variety of reasons it is worthy goal

Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by Mystery-Machine on Monday May 29, 2023 @10:36AM (#36114421)
"Better interactivity" is subjective. You could argue that faster is better. Expanding and collapsing sections can be achieved faster and with zero JavaScript (which also makes it work on browsers with disabled JS) with a hidden input[type="checkbox"]. Aa for the media viewer, it could be a great exercise to try and make it in a similar manner with input[type="checkbox"] for opening/closing media viewer and input[type="radio"] for switching to prev/next image. This one probably requires browsers to support the `:has` CSS selector.

Also, if you want to further speed up your site, just like you said, the fastest way to speed up the site is to delete JavaScript, get rid of jQuery.

Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by 6510 on Monday May 29, 2023 @10:46AM (#36114511)
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by toast0 on Monday May 29, 2023 @12:33PM (#36115459)
Oooh, that's lovely. I have a page with ~50 lines of javascript to do this, and it looks like I can make it zero lines of javascript instead.
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by 6510 on Monday May 29, 2023 @12:53PM (#36115649)
One could use js to push the state into the url.
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by toast0 on Monday May 29, 2023 @12:58PM (#36115698)
It's just opening and closing detail panes (personal recipie site), there's no reason to put the open/closed state in the url.

But if I can do it with all html, that's better than a function to add / remove a css class and document.onclick = a function to find which recipie you clicked on and adjust the css class.

Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by 6510 on Monday May 29, 2023 @02:16PM (#36116462)
Probably more useful for a nested menu. The default thing almost works out of the box. You need some css to set a proper cursor and style the clickable text properly.
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by janpio on Monday May 29, 2023 @10:47AM (#36114525)
You are not wrong.

I assume the author of the blog post just wanted to optimize the current situation, not completely change how these features work (which would most probably be a much more elaborate change).

Same for dropping jQuery - that will probably be a few weeks or months of work in a codebase the size of Wikipedia/Mediawiki.

Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by robertoandred on Monday May 29, 2023 @09:39PM (#36120256)
Using inputs like that is incorrect in terms of accessibility.
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by exabrial on Monday May 29, 2023 @10:21AM (#36114271)
None of those things actually enhance the website. The only time people "use" them is by accident.
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by muspimerol on Monday May 29, 2023 @10:27AM (#36114330)
Hard disagree, I use the hover-to-preview-article feature all the time. Sometimes I just want to peek at a page to see what it is instead of opening it.
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by janpio on Monday May 29, 2023 @10:28AM (#36114345)
I don't think that is true.

On Wikipedia's mobile view, collapsed sections are super useful (as the table of contents is not visible via the sidebar) and media viewer makes it possible to view details of an image/thumbnail without navigating away from the page.

Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by iggldiggl on Tuesday May 30, 2023 @07:33AM (#36123598)
> collapsed sections are super useful (as the table of contents is not visible via the sidebar)

Yes and no. On the hand some sort of table of contents is useful (but note that you could also just display it inline, the way it used to be done in previous desktop skins), on the other hand those collapsed sections break scroll position restoring when reloading the page after somebody (your browser or directly the OS) kicked it out of your RAM. This is because your (absolute) scroll position depends on which sections where expanded and which collapsed, and that information gets lost when the page reloads – all sections end up collapsed again and the scroll position your browser remembered no longer makes sense.

(There is some sort of feature that tries to restore the section state, but a) it only works within the current session, but not if the OS low memory killer kicked the whole browser out of your phone's RAM and b) even when it does work, it runs too late in relation to the browser attempting to restore the previous scroll position.)

So now that the mobile Wikipedia's full JavaScript no longer runs on e.g. older Firefoxes (e.g. one of the last pre-Webextension versions), the lack of a TOC is somewhat annoying, but other than that, somewhat ironically my browsing experience has become much, much better now that my browser can finally reliably restore my previous scroll position because now all sections are permanently expanded.

Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by shepherdjerred on Monday May 29, 2023 @12:08PM (#36115237)
Is Wikipedia really a significant offender here?
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by hutzlibu on Monday May 29, 2023 @01:10PM (#36115824)
"Both seems like reasonable use cases for interactivity that is (better) achieved using Javascript."

Only if you want fancy animations. I sometimes do, but I think wikipedia can do without(and they don't) and use <details>

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/de...

And media viewer I would naturally do with js as well, but I am certain you can also do it easily with CSS. (Many ways come to mind)

Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by Someone1234 on Monday May 29, 2023 @01:40PM (#36116134)
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by hutzlibu on Tuesday May 30, 2023 @04:03AM (#36122279)
That's a good, or rather bad point. I mean you could probably make a legacy version only, but itnis probably not worth the effort.
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by extra88 on Monday May 29, 2023 @01:35PM (#36116081)
I love details/summary and want them to succeed but current implementations have some issues. A big one is VoiceOver for iOS currently what they are or their state, something that's very straightforward and reliable when making a custom disclosure widget.

Good article about some issues (with a link at the top to his previous article about them). https://www.scottohara.me/blog/2022/09/12/details-summary.ht...

Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by gwern on Monday May 29, 2023 @01:27PM (#36115998)
The sections could be collapsed by CSS by default without render-blocking JS, and adding a media viewer to random media bits and pieces can definitely wait until later. So time-to-interactivity is unnecessarily hampered here.
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by robertoandred on Monday May 29, 2023 @09:37PM (#36120244)
Except collapsing them by default makes them inaccessible to people/crawlers that aren't using JS.
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by gwern on Wednesday May 31, 2023 @10:48AM (#36139041)
Who is using mobile without JS? They are going to have many problems beyond collapses... Likewise, crawlers these days generally run with JS enabled in a browser/VM because so much breaks completely if JS is disabled. This is not a real problem, sorry, NoScript fans.

(Anyway, if you are using CSS + the relevant semantic HTML elements, it can be more accessible, not less, because you are expressing priority and emphasis, so they can skip over collapsed stuff. Although I have my doubts whether screenreaders etc make any good use of it, given that they apparently still do not do basic things like stripping soft hyphens.)

Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by l5870uoo9y on Monday May 29, 2023 @02:20PM (#36116485)
And not to forget preview popups when hovering a link (thought it would be even if they implemented preview modals like https://gwern.net).
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by whaleofatw2022 on Monday May 29, 2023 @10:19AM (#36114258)
To dynamically display data to guilt you into donations?
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by kome on Monday May 29, 2023 @10:16AM (#36114223)
good question that most developers cannot answer.
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by madeofpalk on Monday May 29, 2023 @10:22AM (#36114283)
At least, the ones that don't read the article cannot answer.
Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by haburka on Monday May 29, 2023 @02:12PM (#36116420)
Wikipedia probably wants to support every user of the internet, which means even very old browsers. You can’t rely on relatively new CSS features when supporting browsers that are 10 years out of date.

The fact they’re still using JQuery, probably for similar compatibility reasons is good evidence of that.

Now there are ways to use polyfills that only load when necessary but just about everything is very difficult at wikipedias scale. We can’t solve their problems from an armchair.

Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by EMM_386 on Monday May 29, 2023 @05:42PM (#36118447)
> The better question is: Why use Javascript at all for a static website?

I've been developing websites professionally since 1996. HTML/CSS/JS and SQL.

I am still amazed there is the crowd out there who is "anti-JavaScript". They run NoScript to only allow it in certain places, etc.

It's 2023, a small amount of JavaScript on a page isn't going to hurt anyone and will (hopefully) improve the UX.

For the record, the last site I deployed as a personal project had 0 JavaScript. It was all statically generated HTML on the server in C#/Sqlite that was pushed to Github Pages. So I get it, it's not necessary.

For my little personal site. I'm also the senior lead on an enterprise Angular project.

JavaScript is fine, it's not going anywhere.

And yes, there are way too many React (specifically) websites that don't even need a framework at all, but it's become the go-to. That annoys me too. But some JavaScript in 2023 is fine.

Re:300ms Faster: Reducing Wikipedia's Total Blocking Time by mnw21cam on Tuesday May 30, 2023 @11:51AM (#36126300)
I won't argue that JS doesn't add something to the web experience. My main reason for having JS switched off by default is because JS adds something to the web experience. Namely, a whole load of annoying things like outrageously illegal cookie banners, adverts over the top of the content you're trying to read, auto-play videos on an unrelated topic when you just want to read the article, paywalls, "invitations" to have notifications or sign up to a newsletter, browser fingerprinting, active tracking, and outright malware.

It's a signal to noise ratio thing. There's a small reason to have JS switched on and a large reason to block it. I'd love it if the reason to have JS switched on was even smaller, and that is in fact the recommendation (that JS should enhance an otherwise functional site). I enable JS on sites where I regard the reward as worth it, but most of the time it just isn't, and I don't trust all the rubbish that gets included in the average site.