3 ms·
When the CSS is only to be used when JavaScript runs, I'm okay with using JavaScript to make it active. Again, the media query only does its thing when the brow
by extra88 2y ago
When the CSS is only to be used when JavaScript runs, I'm okay with using JavaScript to make it active. Again, the media query only does its thing when the browser says JavaScript isn't supported, if the page's JavaScript doesn't run because the .js file was blocked or there was a network issue, you get the "JavaScript styles" without the JavaScript.
Yes, there's probably been enough device performance to handle things like :has() and CSS nesting for a while. Another factor may have been IE; as long as there was a browser that wouldn't add features but still had to be supported, interest in expanding CSS spec in ways that couldn't easily rely on CSS parsers ignoring code they don't understand may have been limited.
- throwitaway1123 2y ago> Again, the media query only does its thing when the browser says JavaScript isn't supported I get how it works, it just feels like a hack designed to work around a missing feature, rather than the ideal way to handle the problem. Phrased another way: if the scripting media query was ubiquitous I would never go back to toggling classes via JS. > Another factor may have been IE; Browsers have been shipping features that don't work in IE for the better part of the last decade. If you think CSS nesting would break IE, imagine what IE would do when it encounters a modern JS feature that can't be polyfilled like Proxies.
- extra88 2y ago> if the scripting media query was ubiquitous I would never go back to toggling classes via JS I am asserting that in the majority of cases where a person's browser is not running a page's JavaScript, it is because of a network failure or intentional blocking, neither of which can be detected by the media query. Therefore, three years from now when the media query will be ubiquitous, it won't prevent your styles that are meant to be used only with your JavaScript from being used most of the time.
- throwitaway1123 2y agoThe `@media (scripting: none)` query absolutely can detect if a user has disabled JS on the page via their browser's settings (e.g. via chrome://settings/content/javascript). If you mean to say that it can't detect when a third party extension has disabled scripts, well then I would say that's personally out of scope for me. Extensions can do all sorts of nefarious things, the least of which is disable JS. As far as network reliability is concerned, if the user can't download fonts, media files, stylesheets, scripts, and linked pages, then toggling classes is probably the least of my concerns.