I know how <link type="stylesheet" href=".." /> and <script type="text/javascript" src=".." /> work. But I have some truble understanding where they should be in context of W3C and also in context of good programming practice. I was many examples where these are in the header. I don’t know why, but seems legit. But what impact has it when they’re somewhere else in the HTML code?
Take for instance a header file, that is included by PHP into all pages of a website, and this header file has its own CSS\JS files. So they can either be included in the header file itself, and then there will be a link and a script tag in the middle of the HTML body of the page including the header file. Another option is putting these in the head section of each file, but then changes will have to be made in every single page.
My questions:
- Where should the
linkandscripttags be according to W3C? - What impact will it have if they are in the middle of the HTML body like in the example above?
- What is the best solution in terms of good programming practice?
- How do I make the following
include, while having a W3C compliant page, and in a way that I don’t have to update each page when I change the CSS\JS file.- Consider the included code snippet to be independent of the including page.
Just for clearness a short example: (Consider same situation also for a JS file)
header.html:
<link rel="stylesheet" href="header.css" /> <!--- Should this be here? --->
<nav>
<ul>
<li>Menu item1</li>
<li>Menu item2</li>
</ul>
</nav>
index.php:
<html>
<head>
<link rel="stylesheet" href="header.css" /> <!--- Or should it be here? --->
</head>
<body>
<?php include('header.html'); ?>
<!--- Some HTML code ---->
</body>
</html>
header.css:
nav{ color: #00FF00; }
Simple
For javascipts
FYI:
http://developer.yahoo.com/performance/rules.html#css_top
http://developer.yahoo.com/performance/rules.html#js_bottom
[EDIT]
For your new question,
flushing it out) using ob_get_contents.
Some frameworks, like zend allows you to control this with the helpers.