Sounds like a really good idea. Rick
> -----Original Message----- > From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of > GasGiant > Sent: Monday, August 25, 2008 9:49 AM > To: jQuery (English) > Subject: [jQuery] Re: Best practices for including Jquery > > > I load site wide code in the <head>, but since the header is an > include file that is the same for every page, I also use .getScript() > to load page specific code for forms, plug ins, etc. where they are > needed. I put the page content in a <div> with an id element specific > to that page and only load the code if that id is found in the page, > e.g. if the page has a form then I load the validate plug-in, and if > that form has a date field I might load the datepicker plug-in, too. > > Example: In this site I use the accordion menu and some of the element > inside of the section have hidden elements, so jquery.js and > accordion.js (and .css) are load in the head of all pages. When the > document is ready, I hide the hidden menu items, give them a toggle > event, and then look to see if there is an id="orderform" in the page. > If there is, that's when the order.js script gets loaded with the code > to handle the form. The validation and datepicker scripts are loaded > from inside of the order.js. I find this very efficient. I think of it > as "cascading javascript" :-) > > $(document).ready(function() { > > $('.hide').hide(); > $('[EMAIL PROTECTED]').click(function() > { > $(this).next().toggle(); > return false; > }); > if($("#orderform").length) { > $.getScript("order.js"); > } > }); > > > > On Aug 24, 9:28 am, ripple <[EMAIL PROTECTED]> wrote: > > > > But I think it also might have to factor into how a webpage is built. If > > you have a header, left nav, > right nav, but only need a script for the main content and not for every > page than I might write the > script inside of the content(include) page, although I don't like doing that > cause it's considered, non- > compliant. > > No virus found in this incoming message. > Checked by AVG - http://www.avg.com > Version: 8.0.138 / Virus Database: 270.6.7/1632 - Release Date: 8/25/2008 > 7:05 AM