Order of tags in <head></head>

前端 未结 14 738
Happy的楠姐
Happy的楠姐 2020-12-24 10:58

does it matter at all what order the or

14条回答
  •  被撕碎了的回忆
    2020-12-24 11:29

    Optimization

    According to the folks over at Yahoo! you should put CSS at the top and scripts at the bottom because scripts block parallel downloads. But that is mostly a matter of optimization and is not critical for the page actually working. Joeri Sebrechts pointed out that Cuzillion is a great way to test this and see the speed improvement for yourself.

    Multiple Stylesheets

    If you are linking multiple stylesheets, the order they are linked may affect how your pages are styled depending on the specificity of your selectors. In other words, if you have two stylesheets that define the same selector in two different ways, the latter will take precedence. For example:

    Stylesheet 1:

    h1 { color: #f00; }
    

    Stylesheet 2:

    h1 { color: #00f; }
    

    In this example, h1 elements will have the color #00f because it was defined last with the same specificity:

    Multiple Scripts

    If you are using multiple scripts, the order they are used may be important if one of the scripts depends on something in another script. In this case, if the scripts are linked in the wrong order, some of your scripts may throw errors or not work as expected. This, however, is highly dependent on what scripts you are using.

提交回复
热议问题