I'm developing a simple website with a few pages and some javascript (jQuery) scripts. For the CSS I used a single .css file with all the css for every page, and I thought to do the same for the scripts. So in the head of my pages I have this:
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="scripts.js"></script>
<link href="CSS.css" rel="stylesheet" type="text/css">
In this site don't use much javascript, for example in the home page I have only a sort of slideshow with a simple continuous sliding background that I made in this way:
var bgpos=1
function slide() {
$("div.slideshow").css("background-position","0px "+bgpos+"px")
bgpos++
}
setInterval(function(){slide()},35)
I have also a little javascript used in other pages, but I was wondering if it's a good practice to have all the scripts in a single file linked to every page. Here's the main question I was thinking about: if I use that file for every page, will the code above run uselessly in another page without a div.slideshow?
What's the best way to solve this?
I like the fact that the javascript is in a different file from the html, but maybe it's better to put these scripts directly in the head.