[wp-hackers] Including javascript in the footer

Dylan Kuhn dylan.k.kuhn at gmail.com
Wed May 18 00:46:56 UTC 2011


On Tue, May 17, 2011 at 12:37 PM, Otto <otto at ottodestruct.com> wrote:

>
> For example, I could hook to template_redirect, do my detection stuff
> there, and if I determine I need my extra query, then just go ahead
> and create it and pop it into a global for later use.
>

I appreciate the example and will add it to my toolbox, thanks. The thing I
found hard to image was using query_posts(), or multiple "main" queries
before wp_enqueue_scripts. I think I see that you weren't suggesting that as
a likely scenario.


>
> If your script dependencies depend on the results of that query, then yes.
>
> This is a special case though. Generally script enqueueing doesn't
> really depend on the results of a query.


For me it's a specific case, but one I seem to have to consider a lot. Map
libraries, fancy slideshows, table enhancers, and such can all be fairly
heavy on the javascript, but used in a minority of content. It seems like
that content is often as likely to be in a widget or dependent instance of
WP_Query as the main one.

It's harder to make the decision in plugin code, because you have no idea
how much content will need the scripts. Maybe it would be a nice plugin
option to let the user choose their strategy, lookahead or global include.


>  Yes, if
> you're using one of myriad page speed tools, then they'll say to
> reduce the number of scripts you load, but are your visitors really
> only looking at one page on your site at a time, or do they come back
> often? Are you trying to save on bandwidth, or server execution time?
>

I see a possible third consideration: how much script runtime will you
experience when the DOM is ready? I've started noticing delays becoming more
common at this phase of the page load too. I'm not sure how much scripts
that essentially select nothing at this point affect this - probably only if
they're doing something wrong.

-dylan-


More information about the wp-hackers mailing list