<html lang="en" class="no-js">
...
<script type="module">
document.documentElement.classList.remove('no-js');
document.documentElement.classList.add('js');
</script>
It's so simple but so effective. Will be copying that. <html lang="en" class="no-js">
...
<script type="module">
document.documentElement.classList.remove('no-js');
document.documentElement.classList.add('js');
</script>
It's so simple but so effective. Will be copying that.Edit: To be clear, Modernizr isn't a big library like jQuery and you can specify the thing you want to detect, so you can cut it down, but it's still pointless if you just want to know if JS is enabled or not.
Basically, serve a page with formatting done via table layout, and then rewrite it with javascript in the client to use more modern layout tools, depending on which features were available on the browser.
<noscript> is pretty much a feature of the HTML parser. It disappears. The DOM representation doesn’t include a <noscript> element, so you can’t style it. (This is also why you can’t use <noscript> in the XML syntax of HTML. If you don’t know about the XML syntax, I’ll simplify and say it roughly means what was commonly called XHTML.)
What makes it even less useful is that the absence of the <noscript> content doesn’t mean that your scripts are being executed. If you use something like uMatrix or uBlock Origin to block certain types of scripts, for example, you might find that none of the scripts execute, but that the <noscript> content is also not loaded, because it could have executed some scripts, if the right URLs had been requested. Or perhaps the browser was happy to execute JavaScript, it’s just that it failed to fetch the JavaScript, for whatever reason. (Perhaps you put your JS on a CDN, on a different origin, and it’s down.)
In the end, the .no-js approach is far superior to the use of <noscript>.
Of course, if your app breaks because of browser extensions, you should handle errors gracefully, but that goes beyond the no-js classname.
I just posted this since I haven't seen it mentioned and it's fairly useful.
I read that as “you can apply CSS to a <noscript> tag”, which is false. Stuff within it, sure. But the <noscript> tag itself vanishes during document parsing.
I maintain my position: <noscript> is nowhere near as useful as it first appears, and should seldom be used.
I would even suggest that, excluding spiders, user agents that don’t run some or all JavaScript will normally be due to browser extensions. This is a fairly niche area overall, and various extensions are the main factor.
To be clear, the noscript tag "disappears" when javascript is enabled in the browser. When javascript is disabled it behaves like any other tag and can be styled accordingly.
Extension can disable scripts selectively but in that case javascript is still considered enabled for the purposes of the noscript tag.
This is wrong. In case the browser does not have JS (enabled) its a normal element.
I apologise for misleading people.
Web developers don't do graceful degredation anymore.
edit: uBlock Origin shows <noscript> when the entire site's JS is disabled.
Conceptually it's a lot easier to manage if they're fully distinct, or at least if the common bits are explicitly common.
Edit: Your blog doesn't even use SSL...
I’ve had the “how to deal with folks who disable JavaScript” discussion for well over 10 years and the answer in every shop I’ve worked in has always been the same... don’t bother. And it was the developers themselves making that call, not the “business people”.
But yeah, GP, get a Let's Encrypt certificate for the sake of your readers!
What http site is left we can go to when isp or WiFi greets with a welcome login page. Going to https sites gives an error.
You are also welcome to use my html boilerplate:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="blue-white.css">Otherwise… example.com, maybe. I guess we'll see how long the http version of that lasts.
I assume ISPs will get around to this a few decades after implementing IPv6.
> [not] for a decade
Agreed, probably longer. How old is Modernizr?
Who asked?