Add a noscript fallback for critical features
Add a noscript element for features that need JavaScript, and a class on html that scripts swap, so the page degrades to something usable.
If the script fails or is blocked, a page that depends on it should say so and offer another route. <noscript> and a class on the root element cover both cases.
<html class="no-js">
<head>
<script>document.documentElement.className = 'js';</script>
<style>
.no-js .needs-js { display: none; }
.js .only-no-js { display: none; }
</style>
</head>
<body>
<noscript>
<p>Search needs JavaScript. <a href="/sitemap">Browse the sitemap instead.</a></p>
</noscript>
<form class="needs-js" id="search">...</form>
</body>
</html>console.log(document.documentElement.className);jsThe inline script runs before anything paints and replaces no-js with js, so CSS hides the controls that do nothing without scripts. The <noscript> content is shown only when scripting is disabled. Both approaches are described in the noscript element.
This does not help when the script is blocked halfway, for example by a failed network request. Design forms to work as plain HTML first, such as a real action and method, and enhance them with JavaScript. A search box that submits to /search?q= works with no script at all.