skip nav


Same Script, Multiple Tags

Today, I happened on a fun quirk of web-dev. What happens if you include the same script twice, say like this:

<!DOCTYPE html> <html lang="en"> <head> <script src="test.js" type="module"></script> <script src="test.js" type="module"></script>

test.js only runs once, despite being included twice. It seems modules have a specific trait where they're only ever evaluated once, I believe specified in steps 4 and 5 of ECMAScript 6.0 section

Nothing good ever comes of running scripts multiple times. I'm glad it's out.

P.S.: Fun fact: You can still document.write(…) in an ECMAScript module, which just feels… wrong. (At least the with statement is history there, as modules are always in strict mode.)

tags: js, quirk, microblog, web dev