Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress WordPress Theme Development Working with CSS and JS in WordPress Themes How to Link to JS from functions.php File

Devinder Sodhi
Devinder Sodhi
5,493 Points

why is it that you put the javascript enqueue without the jquery dependency in the header?

in the video, when we enqueue scripts, we make a distinction to load javascript files without dependencies at the header, and jquery dependent files in the footer via the "true" or "false" parameters in the enqueue functions. why is this?

Richard Walton
Richard Walton
10,861 Points

Yes, I would like to know as well? It was just glossed over in the video

1 Answer

Kevin Hamil
Kevin Hamil
8,203 Points

Here's a more clear answer... deleted my previous one.

Wordpress ships with the most recent version of jQuery at the time of the WP release.

In the video (at 4:00), Zac didn't create a specific enqueue call for jQuery because he instead set it as a dependency of another enqueue call. Foundation.js requires jQuery to run, so Zac put jQuery as a dependeny of foundation.js, which tells WP to load jQuery before it loads foundation.js. This is cleaner and less code, but you could still create an enqueue call for jQuery if you weren't setting it as a dependency of another enqueue call.

Also, he set the last parameter to true, which tells WP to insert this script into the footer instead of the head. The benefit of loading scripts in the footer is page load time. If all of your scripts load in the head then the page waits for those to complete before it renders your page html. This can cause lag or slow page loading. So by calling scripts in the footer that are non-essential to rendering your page, your page loads faster. In the case of modernizr.js, it affects how your page renders, so you would want that to load in the head before the page renders.

I hope that's more clear.

Devinder Sodhi
Devinder Sodhi
5,493 Points

I think i understand better now. Thanks!

Thanks, this cleared some questions up for me!

Scott Chen
Scott Chen
8,026 Points

Great answer, Kevin.