Here is my understanding of how all of this magic works (PLEASE correct me if I am wrong):
In a PHP/JS/HTML/CSS website, when a page is requested, the server reads the file(index.php for referencing purposes of this question), executes any <?php ?>
tag/construct and does the work. It then send the completed work to the requestor, as one complete page. The requestor then reads the file (via a browser) and executes the file (index.php) in the "normal" order. If I want several pages to include the same JS scripts and libraries, can I include (safely and ok with convention) the JS:
<script type="text/javascript" src="LIBRARY/1.js"></script>
<script type="text/javascript" src="LIBRARY/2.js"></script>
// etc... for libraries, then also include inline scripts like:
<script type="text/javascript">
$(document).onLoad(function(){
});
</script>
<script type="text/javascript">
$(document).ready(function(){
});
</script>
via a PHP include:
<!-- JS -->
<?php include ("component/js.php"); ?>
If this is possible, is it also best to include these at the bottom of the page, or should libraries be at the bottom, onLoad
be at the top, ready
at the bottom, or any other specific location for load time optimization?