According to the Codex:
wp_enqueue_scripts()
links a script file to the generated page at the
right time according to the script dependencies, if the script has not
been already included and if all the dependencies have been
registered. You could either link a script with a handle previously
registered using the wp_register_script() function, or provide this
function with all the parameters necessary to link a script. This is
the recommended method of linking JavaScript to a WordPress
generated page.
So we can say it’s none but a good practice.
As per the WordPress theme reviewers, wp_enqueue_scripts()
is recommended, or may be mandatory, because one of the reviewer, reviewed my theme, said:
Themes are required to enqueue all stylesheets and scripts, using
wp_enqueue_style()
/wp_enqueue_script()
, and hooked into an appropriate hook via callback function, rather than hard-coding stylesheet/script links or tags in the template.
But after all, all your confusions related to the enqueue scripting will be vanished after reading:
- How to Include JavaScript and CSS in Your WordPress Themes and Plugins
- The Ins and Outs of The Enqueue Script For WordPress Themes and Plugins
But quoting the main reasons here for a quick look:
Why Do We Use The Enqueue Function?
…but once you introduce the myriad of other scripts that might potentially run on a WordPress installation, it gets trickier to do what I’ll call “crowd management” with your scripts. So why not load your JavaScript in the Header or the Footer? The answer is pretty simple: By including your JavaScript like that, you run the risk of having conflicts with your JavaScript across your installation (think, multiple plugins trying to load the same scripts, or different versions of that script). Furthermore, your JavaScript will load on every page, even if you don’t need it to. This will cause an unnecessarily longer load time for you pages, and can interfere with other JavaScript, like from a plugin or within the dashboard… and that’s a No No in WP development. By using the wp_enqueue_script function you’ll have better control with how and when you load your JavaScript. You can even decide whether to load into the header or footer.