What is the general opinion of developers about including javascript code in a file instead of including it in a script tag.
So, we all agree that jquery needs to be included in the script file, as shown below:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script>
My question is to get features on a page that is not on all pages of the site. Will we include functions like below on the same page or in the global include file, as indicated above, mysite.js.
$(document).ready(function(){ $(".clickme").click(function(event){ alert("Thanks for visiting!"); }); });
OK. Thus, the question is: if the above code is called in each class = "clickme" on certain pages, and you have the opportunity to call it either from a separate file named mysite.js, or to the contents of the page. How will you go?
Arguments:
If you include it in a page, you will only call it from those specific pages where the js function is needed.
Or you include it as a file that is cached by the browser, but then jquery will have to spend x ms to know that this function does not start on a page without the "clickme" class.
EDIT 1: OK. One point that I want to make sure people are referring is that the result of the document.ready function being called things that don't exist on the page, will there be any delays in the browser? Is this a significant impact?
source share