Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I place conditional comments in the bottom of my html document? (in the body) or should it be in the head?

<script>if(BrowserDetect.browser=="safari"){document.write('<link rel="stylesheet" href="css/safari.css" type="text/css" media="all" />')}</script>

<!--[if lte IE 8]><link rel="stylesheet" type="text/css" href="css/pie.css" /><![endif]-->

Can I place conditional comments in the bottom of my html document? (in the body) or should it be in the head?

Placing those in the bottom is better in terms of page speed or not?

like image 421
Damian Avatar asked Jan 14 '23 02:01

Damian


1 Answers

You can have conditional comments anywhere. Only the specified version of IE will parse the contents. In this case, where you have CSS in your conditional comment, it should be in your <head>.

Also, it's not a good idea to use JS to insert a stylesheet. The user will see the unstyled (or incorrectly styled) content until the document.write fires, and the css file loads. Insert with a server-side script such as PHP first.

like image 85
Mooseman Avatar answered Jan 15 '23 15:01

Mooseman