Once you’ve been working on WordPress-based projects for a while, you quickly learn how to properly include stylesheets and JavaScript dependencies for the administrative dashboard or the public-facing aspect of a theme or plugin.
That is, you’re familiar with admin_enqueue_scripts
and wp_enqueue_scripts
.
And although these two hooks provide a way to segment the way in which scripts are loaded, it’s possible to further optimize how JavaScript dependencies are loaded by only loading them on the page that they are required.
Specifically, there are two ways that you can add JavaScript in WordPress in the dashboard: