3 ms·
> We’ll simply create a single class, d-js-required to indicate that JavaScript needs to be enabled for us to display this element. You can run some JS to prov
by theandrewbailey 2y ago
> We’ll simply create a single class, d-js-required to indicate that JavaScript needs to be enabled for us to display this element.
You can run some JS to prove you're running JS. Can't you write in your site's CSS:
.d-js-required { display: none; }
and (in JS) remove that class on each element it's on?
- c0balt 2y agoWouldn't this lead to a delay of time to first content render? If you rely on display then a layout shift would also be an issue for JS-capable clients.
- charrondev 2y agoWrite that tiny of bit of JS inline in the head and put the class/attribute on the html element.
- 0xdade 2y agoThis is absolutely an option! It gets a little tricky to avoid shifting content around, since it's pretty typical to load styles in the head but load javascript either at the end of the DOM or with the defer tag, so the javascript would likely be running after the user has already seen the layout, and layout shifts could be clunky.