I've just started maintaining a very large legacy codebase that uses html5shiv. I notice from the documentation that it is supposed to be declared in a conditional comment after the style sheet links like this:
<link rel="stylesheet" type="text/css" href="/css/example.css">
<!--[if lt IE 9]>
<script src="scripts/html5shiv/dist/html5shiv.js"></script>
<![endif]-->
However in my codebase it is declared before the style sheet links and without the conditional comments like this:
<script src="scripts/html5shiv/dist/html5shiv.js"></script>
<link rel="stylesheet" type="text/css" href="/css/example.css">
I'm just trying to get a better understanding of why the docs recommend declaring in a comment and after the css. Is not doing so going to cause any trouble and if so what sort? The reason I ask is I was considering removing it due to us no longer supporting old versions of IE and was wondering if doing so is likely to cause any issues in newer browsers.
the conditional comments only load the html5shiv code on the condition that the version of Internet Explorer is lower than 9. Other browsers, such as Firefox and Chrome, will also ignore this tag and won't execute the script, thus saving bandwidth.
html5 shiv is based on a simple workaround: it directs IE to create the elements with JavaScript (they don't even need to be inserted into the DOM).