<script type="module"> document.documentElement.classList.remove('no-js'); document.documentElement.classList.add('js'); </script>
type="module" attribute makes sure that only modern browsers with
I had never come across a
<script> element with a
that was not linking to the URI of an external script and I was wondering if
this was some sort of hack. So I tried the following snippet.
<script type="module"> const body = document.body; body.style.backgroundColor = 'deeppink'; // beautiful </script> <script type="module"> body.style.backgroundColor = 'purple'; // Uncaught ReferenceError: body is not defined </script>
const body defined in the first module is available only in that module
and trying to use it in the second module results in an
Uncaught ReferenceError: body is not defined. So of course it is not a hack.
It is behaving exactly as you would expect.
The original website no longer exists 😔. Thankfully there's the Internet Archive. ↩︎