That's something that each developer has to evaluate on their own. I'd think
it depends on the size of the file, and how it's being served.

Better for SEO to have an external file, as content is now closer to the
top.
Better for the user to cache said file.

Maybe set your own personal threshold for size...if the file is over 5k,
externalize it?


andy

-----Original Message-----
From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
Behalf Of kgosser
Sent: Tuesday, April 14, 2009 10:52 AM
To: jQuery (English)
Subject: [jQuery] Re: Should $(document).ready() be external? And should it
be placed at the bottom of the page?


So do you think placing it in an external file poses caching benefits that
outweigh the extra HTTP request? The number of HTTP requests seems to be the
biggest killer with speed....

On Apr 14, 10:34 am, "Andy Matthews" <li...@commadelimited.com> wrote:
> You can externalize the document.ready call if you choose, I do it all 
> the time.
>
> As for putting it at the bottom of the page, I'd say no. Putting it in 
> an external JS file, with the ready call makes it so that code is not 
> run until the entire DOM is ready anyway.
>
> andy
>
> -----Original Message-----
> From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] 
> On
>
> Behalf Of kgosser
> Sent: Tuesday, April 14, 2009 10:28 AM
> To: jQuery (English)
> Subject: [jQuery] Should $(document).ready() be external? And should 
> it be placed at the bottom of the page?
>
> Hey all,
>
> Two quick questions for you. I couldn't find the answers while
searching...
> This would be a great thing to add to the jQuery FAQ, by the way.
>
> (1) Is it advisable to place a page's $(document).ready() stuff in an 
> external .js file?
>
> I've been doing a lot of reading and research on optimizing my front 
> end code, and YSlow seems to make a big deal of placing code 
> externally if possible for caching reasons. I understand the 
> usefulness of placing the code in an external document for that 
> reason, however, the problem is that there are a lot of functions for 
> button and link clicks, shows/hides, etc., that are unique to that page
and used differently on other pages.
>
> Thus, putting it externally means it would most likely have to be in 
> an independent file just for that page... which means an added HTTP 
> request which is really the speed killer.
>
> So anyways, looking for thoughts on this one.
>
> (2) Is it advisable to place the $(document).ready() at the bottom of 
> the page right before the closing BODY tag?
>
> Also when doing my research, I've seen that YSlow makes a big deal of 
> this as well. I'm sure many of you on here have discussed it or 
> thought about it yourself.
>
> My question though is does it make sense to put the ready() code at 
> the bottom? Does it help? Is it useful? Will it break?
>
> Thanks in advance for any feedback. Take care everyone.


Reply via email to