I'm approaching this from a performance and usability point of view. I've found that every fraction of a second I can shave off of the load time results in more pages per session, so the main goal is for the page to load faster for the end user, and be usable faster.
I have several scripts that are currently like:
<?php
echo <<<EOF
<div id="example">
EOF;
include 'example.php';
echo <<<EOF
</div>
<script>
setInterval("$('#example').ajax('example.php')", 100000);
</script>
EOF;
?>
Please forgive any typos, that's just written for the example. But the concept is that I include
example.php via PHP, then update it every so often via the setInterval...ajax script.
What I'm wondering is, would it be faster, or better for the end-user, if non-essential things that were loaded like this were not included via PHP at all, but just loaded using the Ajax:
<?php
echo <<<EOF
<div id="example"></div>
<script>
// not 100% sure whether I should wrap this in $(function()... ?
$(function() {
$('#example').ajax('example.php');
});
setInterval("$('#example').ajax('example.php')", 100000);
</script>
EOF;
?>
I know that THESE sections wouldn't load until the rest of the page is loaded (if I understand correction, $(function()... means that they won't begin to load until the document is complete?), and they would rely on the user to have Javascript enabled, but if they're not essential to the page then would that matter?
(Note, by "non essential", I'm referring to things like, using this site as an example, the "You have mail" script at the top of the page, or the entire right column... useful, but not critical to use the site.)
My theory is that the rest of the page would load faster, and thus be usable more quickly. Or am I wrong, and everything would be at a standstill until those sections loaded, resulting in a longer time before it's usable?