The <Noscript> Element as a Trap(hacktivis.me) |
The <Noscript> Element as a Trap(hacktivis.me) |
The WHATWG recommendation:
it's generally better to avoid using noscript, and to instead design
the script to change the page from being a scriptless page to a
scripted page on the fly,
is fine as it is, but changing the page after scripts load can potentially mean seeing the no-script content briefly (FOUC - Flash of Unscripted Content). Putting the message in a <noscript> tag avoids that.These days you can use CSS to only show the message after a short delay.
But the majority of websites have no business actually requiring JS so the W3C recommendation is the only one that matters.
<if js is available>
...
<else>
...
<the closing tag i guess/> <script>
...
</script>
<noscript>
...
</noscript> <script src="..." id="bla></script>
<noscript for="bla">Script not loaded</noscript>
Would be more flexible, and would be consistent with how labels, datalists, etc. are linked to their element.Either way, make sure you have something sensible to display for all scenarios, even if it's just an error page. Mysterious blank pages are not fun.
Any no-JS extension worths its salt should actually at least provide an option to ignore <noscript> as some websites that would otherwise work perfectly fine without JS use it maliciously.
The most infuriating one is when the javascript deletes the entire page content to show an error message due to some exception. Doubly so when the failing functionality is only used for tracking or some other unwanted "feature".
> “One of the few traps of the web”
…for some large value of “few”
The author answered their own question. In even the best effort case, noscript is the fallback.
I'm not even sure what they expect the website maintainer to do for most of that list. If they knew themselves, they would have put it in the blog post. Is this instead a call to draft new w3c specs or revisions? What am I misunderstanding? For a site that has "hacktivism" in the domain name, whining like this is a bad look.
> For this reason, it's generally better to avoid using noscript, and to instead design the script to change the page from being a scriptless page to a scripted page on the fly
That seems perfectly reasonable for modern sites and browsers to be able to do. `noscript` is effectively a relic from older days where you just didn't have the same budgets, tools, and browsers as today, where you couldn't seamlessly enhance the site how you can now. We shouldn't continue to use it in the same way we shouldn't continue to use `marquee` or `blink`.
The noscript tag is just a way to conditionally display some HTML. There's no reason to avoid using it unless you are deeply entrenched in a pseudoreligious fight against javascript.
It really is just whining.
> didn't have the same budgets, tools, and browsers as today, where you couldn't seamlessly enhance the site how you can now
I'm sorry, but... what?
But writing a page that works by itself and modifying it by scripts will work almost everywhere as long as you add any external dependency in a way that invalidates your script on errors.