For progressive enhancement, web devs should avoid using JavaScript for crucial behavior. However, for accessibility, JavaScript is often necessary to manage focus, set aria-*
states, or manipulating the DOM to show/hide modals, tooltips, and accordion sections.
This means that JavaScript is crucial, even for the most vanilla pages, let alone pages that rely on frameworks. Even Web Components rely on JavaScript.
JavaScript is considered a weak link in progressive enhancement because of a few reasons: External JS files not loading (for whatever reason) and users disabling it (0.2% globally but varying by browser–TOR–and location–East Asia, What percentage of browsers with javascript disabled? - Deliberate Digital). Users that disable JavaScript often do so to avoid tracking. They pay the price by getting an often unusable web experience.
To combat this, I propose a new script
type: <script type="safe">
.
This new type of script can only be declared inline, disallowing linking external scripts. This would fix the “external JS didn’t load” issue because if you got the HTML, you got the inline script.
Secondly, and more importantly, this subset would not have the ability to make network calls or access location
, navigator
, history
, or other sources of identifying data. It would not be able to do things like el.click()
or form.submit()
but it could do el.focus()
and DOM manipulations. If JavaScript were disabled, it wouldn’t be able to insert a new image element or any tag that would make a network call. (I guess the img
tag would be added to the DOM but just show a broken image.)
It would provide enough power to enable Web Components but not enough to enable tracking.