StackOverflow is telling me this is a subjective question, but I think it’s a matter of fact!
I have a number of scripts that I’m using on different parts of my site. In terms of making fewer http requests, I know it’s better to combine all of these scripts into one .js file. However, isn’t a waste of time for a page to call a .js full of 10 or 15 different functions when it’s only using one?
The other method I am using is to use PHP conditional statements…
<?php if( is_page() ) { >
$(document).ready(function(){
...
});
<?php } ?>
What’s the best method or comination of these methods?
I would say, provided you expect users to require the vast majority of these resources as they browse your site, taking the hit all at once isn’t much of an issue.
You need to make sure that your homepage loads quickly enough though, maybe consider a cut down script file for the homepage, and a fully bloated version for the other pages. Or separate out the truly required on every page features into a file that is included on the homepage, and the other features into an -extra file. Then include both files on pages which require them. The browser will already have cached the basic file from the homepage.