[wp-hackers] Including javascript in the footer

Philip Walton philip at philipwalton.com
Wed May 11 16:38:39 UTC 2011


On 5/11/11 6:57 AM, Otto wrote:
> I'm going to go ahead and categorically state that there is no
> situation where it is *necessary* to enqueue a script halfway down the
> page. All the normal data is loaded into memory, the main query has
> executed, the autoloader has occurred for options... what else do you
> need?
I can agree that it's not absolutely necessary to enqueue a script at 
the point in the page load that I'm wanting to. But I still maintain 
that there's nothing "wrong" about it. Putting a script in the footer is 
a very reasonable thing to do, so as long as I'm making that decision 
before I output the footer markup, I see nothing categorically wrong 
with it.

I'm also not making the decision to include the script based on the post 
content (maybe that was unclear). I'm doing so on a settings form form 
the admin side.

The add_settings_page() includes a callback to output the contents of 
the form, and that callback is fired after the admin_enqueue_scripts 
hook. In that callback I'm creating a form object and deciding and at 
that point (based on factors I don't control) whether or not I need to 
either use a script to do ajax form validation.

The most logical place for me to make that decision is in the 
add_settings_page callback. Could I do it before? Yes, but in my 
opinion, that would be doing it the "wrong" way.

Philip


> Starting the Loop early to look ahead at the content that will be
> displayed on the page, following by calling rewind_posts() to reset
> the Loop for later is not "hackish". It's obvious. We have
> rewind_posts() for a reason, you know.
>
> -Otto
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers


More information about the wp-hackers mailing list