Where is the best place for performance to load in the jQUery library on a WordPress site? header.php? footer.php? Thanks
Leave a Reply
You must be logged in to post a comment.
Where is the best place for performance to load in the jQUery library on a WordPress site? header.php? footer.php? Thanks
You must be logged in to post a comment.
YSlow recommendations would say the footer is the best place if you can manage it, because the JavaScript won’t delay loading the page. Put all your JavaScript just before the
</body>
tag. Minify all of them and combine as many as possible to minimize downloads.You can load jQuery in either place, but ideally you want to use WordPress’ built-in function for adding scripts, including jQuery which they already have setup to do. It also allows you to include code in either the header or footer before the closing
</body>
tag.http://codex.wordpress.org/Function_Reference/wp_enqueue_script
Example, put this in your functions.php file and it will de-register the currently included copy of jQuery in WordPress and include the latest version hosted by Google’s CDN:
EDIT: The code example above sets the last argument to “true” which will place jQuery in the footer.