Page 1 of 1

Why don't self-closing script elements work?

Posted: Wed Aug 31, 2022 2:23 pm
by DeepMohinman
What is the reason browsers do not correctly recognize:

<script src="foobar.js" /> <!-- self-closing script element -->
Only this is recognized:

<script src="foobar.js"></script>
Does this break the concept of XHTML support?

Re: Why don't self-closing script elements work?

Posted: Wed Aug 31, 2022 2:33 pm
by Radu
Hi,

There is this XHTML compatibility guideline that browsers obey:

https://www.w3.org/TR/xhtml1/guidelines.html
Element Minimization and Empty Element Content

Given an empty instance of an element whose content model is not EMPTY (for example, an empty title or paragraph) do not use the minimized form (e.g. use <p> </p> and not <p />).
Regards,
Radu