2 Answers
2

Use wp_enqueue_script() in your theme

The basic answer is to use wp_enqueue_script() in an wp_enqueue_scripts hook for front end admin_enqueue_scripts for admin. It might look something like this (which assumes you are calling from your theme's functions.php file; note how I reference the stylesheet directory):

Versioning your Scripts

Also note that above we gave our plugin a version number and passed it as a 4th parameter to wp_enqueue_script(). Version number is output in source as query argument in URL to script and serves to force browser to re-download possibly cached file if version changed.

Epiloque

That's about it for Best Practices of including Javascript files with WordPress. If I missed something (which I probably have) be sure to let me know in the comments so I can add an update for future travelers.

Hook into admin_init instead of asking for is_admin(). Remove the version parameter if you use the Google CDN, otherwise the browser cache will hold two versions: one without the query string from other sites and your's.
–
toscho♦Nov 9 '10 at 23:02

If script two were dependant on script three(ie. script three should load first), this wouldn't matter, WordPress will determine the enqueue priorities for those scripts and output them in the correct order, in short, it all gets worked out automagically for you by WordPress.

I think init is not the proper place to dispatch the enqueue.
–
brasofiloSep 21 '13 at 23:14

Code was originally copied from Mike's answer, then adjusted to illustrate a point. You are correct however, so i've updated the answer to use a better and more correct hook.
–
t31osJan 28 '14 at 14:42