Which of the two HTML snippets perform better?
Including the CSS & JS in the HTML
<html>
<head>
<style>
<?php include("someStyle.css"); ?>
</style>
<script>
<?php include("someScript.js"); ?>
</script>
</head>
OR linking the CSS & JS:
<html>
<head>
<title>Family Tree</title>
<script src="someScript.js"></script>
<link href="someStyle.css" rel='stylesheet' type='text/css' />
</head>
The logic I can think of is
- The server receives fewer hits (+server)
- Parallel transfers are reduced (-browser)
- DEFLATE performance is improved, if used. (+server)
Will I notice an improvement / degradation for large server loads?
You'll get better performance with separate JavaScript and CSS files because they don't change often and so can be cached more aggressively, whereas your HTML is usually dynamic and can't be cached. If you inline your JavaScript and CSS you therefore can't cache them either, which means more data to download and longer page generation time. You probably want to do the following to these separate files however:
Etag
andLast-Modified
headers are set, and that the server honoursIf-Modified-Since
andIf-Not-Match
Expires
header some time in the futureWell one example is client side and the other is server side. So, if you prefer better server performance then go with client side in your second example. By the way, your still linking in both examples and not inputting any CSS or JS code in the actual HTML doc. In the first example, you're telling the server to process the CSS and JS code within the PHP tags and in the second example, you're telling the client (your web browser) to process the CSS and JS code.