News for hackers. Stuff that matters.
Re:My Current HTML Boilerplate by tsujp on Tuesday April 27, 2021 @02:44AM (#26952806)
I've never thought to do something like this as a way to detect whether or not js is being used.

    <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.
Re:My Current HTML Boilerplate by dan1234 on Tuesday April 27, 2021 @02:51AM (#26952844)
I first saw that technique used by Moderinizr, which was a very useful tool back in IE8 days!

https://modernizr.com/

Re:My Current HTML Boilerplate by gerardnll on Tuesday April 27, 2021 @03:40PM (#26960486)
Website is unmaintained, check the Github repo for the lastest version.

https://github.com/Modernizr/Modernizr

Re:My Current HTML Boilerplate by jojohohanon on Tuesday April 27, 2021 @12:26PM (#26958112)
There was a post on Metafilter highlighting a similar approach to graceful javascripting, back when javascript was a question, not an answer.

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.

Re:My Current HTML Boilerplate by ok123456 on Tuesday April 27, 2021 @11:52AM (#26957610)
What's wrong with using modernizer now?
Re:My Current HTML Boilerplate by frereubu on Tuesday April 27, 2021 @03:05PM (#26960059)
As long as you don't have to deal with IE11, cross-browser support is much better, partially due to fast release cycles. No point including a whole library if all you want to do is detect whether JS is enabled.

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.

Re:My Current HTML Boilerplate by tiborsaas on Tuesday April 27, 2021 @04:58AM (#26953624)
There's even a <noscript> tag since HTML 4.01. You can apply CSS to it too.
Re:My Current HTML Boilerplate by chrismorgan on Tuesday April 27, 2021 @05:57AM (#26953944)
<noscript> is a blunt instrument that isn’t anywhere near as useful as you think it is.

<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>.

Re:My Current HTML Boilerplate by theandrewbailey on Tuesday April 27, 2021 @08:24AM (#26954939)
In uMatrix, there is an option "Spoof <noscript> tags when 1st-party scripts are blocked" that shows <noscript> content.

edit: uBlock Origin shows <noscript> when the entire site's JS is disabled.

Re:My Current HTML Boilerplate by tiborsaas on Tuesday April 27, 2021 @07:01AM (#26954330)
You CAN style stuff you put in <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.

Re:My Current HTML Boilerplate by thesuitonym on Tuesday April 27, 2021 @09:33AM (#26955579)
>Of course, if your app breaks because of browser extensions, you should handle errors gracefully

Web developers don't do graceful degredation anymore.

Re:My Current HTML Boilerplate by deathanatos on Tuesday April 27, 2021 @07:57PM (#26963686)
Apps break even without browser extensions. A huge number of websites try to use localStorage, and do not check for errors. (localStorage will raise if the cookie settings for the UA do not permit storing data.)
Re:My Current HTML Boilerplate by chrismorgan on Tuesday April 27, 2021 @07:09AM (#26954381)
> You can apply CSS to it too.

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.

Re:My Current HTML Boilerplate by ChrisSD on Tuesday April 27, 2021 @07:55AM (#26954709)
I think you're talking past each other.

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.

Re:My Current HTML Boilerplate by FlorianRappl on Tuesday April 27, 2021 @08:00AM (#26954751)
> But the <noscript> tag itself vanishes during document parsing.

This is wrong. In case the browser does not have JS (enabled) its a normal element.

Re:My Current HTML Boilerplate by chrismorgan on Tuesday April 27, 2021 @11:01PM (#26965014)
I was indeed wrong about this. I’d grown used to uMatrix’s spoofing, where it does get changed, and misrecollected things. I have now refreshed my understanding from the spec: it’s still a parser feature in that that iff scripting is enabled, it parses its children as raw text (like <script> or the old <xmp>). (And then there’s the user-agent style on it, `display: none !important`, so that you can’t get it to appear whatever you do, unlike most normally-hidden tags like head, title and script.)

I apologise for misleading people.

Re:My Current HTML Boilerplate by megous on Tuesday April 27, 2021 @08:14AM (#26954852)
Yes, you can see it in the dev tools/inspector.
Re:My Current HTML Boilerplate by blauditore on Tuesday April 27, 2021 @08:44AM (#26955104)
I think this is the most obvious way, no? What approach did you use before?
Re:My Current HTML Boilerplate by illumanaughty on Tuesday April 27, 2021 @10:11AM (#26956081)
Simple =/= Obvious.
Re:My Current HTML Boilerplate by wnevets on Tuesday April 27, 2021 @12:39PM (#26958295)
I've also used something like this for Internet Explorer 10 detection.
Re:My Current HTML Boilerplate by faitswulff on Tuesday April 27, 2021 @12:15PM (#26957950)
Hmm, why bother even having the no-js class, then?
Re:My Current HTML Boilerplate by Cederfjard on Tuesday April 27, 2021 @12:58PM (#26958544)
Because you can target it with CSS and apply styles specific for when the document is viewed without JavaScript enabled.
Re:My Current HTML Boilerplate by faitswulff on Tuesday April 27, 2021 @01:44PM (#26959092)
Is it too much trouble to just override the base style with the js style? As in, don’t specify the base style with “no-js” at all, just the js overrides.
Re:My Current HTML Boilerplate by mikepurvis on Tuesday April 27, 2021 @02:39PM (#26959771)
Complicates the base case if you need to undo in it any unwanted styled applied in the no-js case.

Conceptually it's a lot easier to manage if they're fully distinct, or at least if the common bits are explicitly common.

Re:My Current HTML Boilerplate by deckard1 on Tuesday April 27, 2021 @02:45PM (#26959838)
most websites are going to be JS-first. If it makes sense for you to augment your site with JS, then sure knock yourself out and reverse it.
Re:My Current HTML Boilerplate by contradistinct on Tuesday April 27, 2021 @12:59PM (#26958559)
If javascript isn't running in the browser, the script won't run and the class won't change from no-js to js.
Re:My Current HTML Boilerplate by Ayesh on Tuesday April 27, 2021 @09:27PM (#26964281)
Drupal had this for quite a long time (since Drupal 5 through 8 IIRC), but there was a proposal to remove it.
Re:My Current HTML Boilerplate by nathell on Tuesday April 27, 2021 @04:25AM (#26953423)
I won't. Under my definition, it causes the page to stop being a document and start being an application. Being able to detect JS can be useful sometimes, but, to me, it doesn't belong in a boilerplate.

http://blog.danieljanus.pl/2019/10/07/web-of-documents/

Re:My Current HTML Boilerplate by weird-eye-issue on Tuesday April 27, 2021 @11:31AM (#26957301)
The web is moving on without you.

Edit: Your blog doesn't even use SSL...

Re:My Current HTML Boilerplate by spookthesunset on Tuesday April 27, 2021 @12:07PM (#26957835)
The “documents not applications” battle is like 10 years old at this point. The web moved on a decade ago...

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”.

Re:My Current HTML Boilerplate by weird-eye-issue on Tuesday April 27, 2021 @12:12PM (#26957916)
Yeah I was being nice. It moved on so long ago I'm not sure how he calls himself a developer. Okay there... I said it.
Re:My Current HTML Boilerplate by milkey_mouse on Tuesday April 27, 2021 @02:00PM (#26959268)
Sometimes "the industry" "moves on without" a valuable perspective. That doesn't mean those "left behind" (e.g. Richard Stallman) should give up. Something something "marketplace of ideas."

But yeah, GP, get a Let's Encrypt certificate for the sake of your readers!

Re:My Current HTML Boilerplate by nashashmi on Tuesday April 27, 2021 @02:12PM (#26959412)
OT :

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.

Re:My Current HTML Boilerplate by ziml77 on Tuesday April 27, 2021 @02:40PM (#26959776)
Re:My Current HTML Boilerplate by deathanatos on Tuesday April 27, 2021 @08:00PM (#26963712)
ISPs & WiFi APs can stop trying to attack connections like that, and implement RFC 8910[1].

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.

[1]: https://tools.ietf.org/html/rfc8910

Re:My Current HTML Boilerplate by krazerlasers on Tuesday April 27, 2021 @04:26PM (#26961069)
You are welcome to use my site: http://krazerlasers.com

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">
Re:My Current HTML Boilerplate by depressedpanda on Tuesday April 27, 2021 @02:38PM (#26959751)
Re:My Current HTML Boilerplate by cjohansson on Tuesday April 27, 2021 @03:50PM (#26960615)
"You can't argue with popularity. Well, you could, but you'd be wrong!" - Robbie Williams
Re:My Current HTML Boilerplate by stedaniels on Tuesday April 27, 2021 @02:53AM (#26952858)
Not to bring you down, but to let anyone else know, this isn't novel and has been standard practice for a decade or so.
Re:My Current HTML Boilerplate by elaus on Tuesday April 27, 2021 @03:01AM (#26952918)
The technique as it isn't new of course, but I doubt this specific implementation (checking for module-supporting JS) is standard practice for a decade.
Re:My Current HTML Boilerplate by greggturkington on Tuesday April 27, 2021 @09:40AM (#26955663)
This doesn't check for "module-supporting JS"

> [not] for a decade

Agreed, probably longer. How old is Modernizr?

Re:My Current HTML Boilerplate by weird-eye-issue on Wednesday April 28, 2021 @10:27AM (#26969737)
Well you're wrong because it does check that it supports modules. Go look at it more closely.
Re:My Current HTML Boilerplate by dt3ft on Tuesday April 27, 2021 @04:20AM (#26953395)
> “To let everyone know, this is not novel”

Who asked?

Re:My Current HTML Boilerplate by RONROC on Tuesday April 27, 2021 @06:44AM (#26954234)
“Not to bring you down, and not adding anything useful here, but...”
Re:My Current HTML Boilerplate by nsonha on Tuesday April 27, 2021 @08:02AM (#26954760)
It is kind of useful. I'm trained to feel dubious of anything newly invented if the underlying elements of the solution have been there for 2 decades (there must be some reason people didnt do it that way then). If this is existing practice then it sounds right.
Re:My Current HTML Boilerplate by _0o6v on Tuesday April 27, 2021 @03:49AM (#26953199)
No it hasn't
Re:My Current HTML Boilerplate by acdha on Tuesday April 27, 2021 @08:25AM (#26954945)
It’s not novel but consider how unproductive your attitude is. Someone was excited about learning something new, and you took a massive dump all over it, with no benefit whatsoever. If you’re upset that not everyone knows everything, you should be working to cultivate that excitement!

https://xkcd.com/1053/