I know about wp_enqueue_script. i just wanted to make sure that it applies here. I built a custom widget that uses a lot of js. Most of that js is included in a separate file that gets included from a switch statement that also runs a query. So for example, if someone chooses a slider from the form in the widget, then the widget gets the slider.php file which has the html and it has the js to run the slider. The issue with this is that when you go into the admin area, you can see all the js in the text editor for that post or page. I am using a page builder to insert the widget.
What I wanted to know. What's the best "Right way" to include the js? should I use the enqueue_script in the slider.php file or is there another way? I was thinking something in the functions.php would work best. Test for the widget to see if it's active and if slider.php was called, then wp_enqueue_script for the .js?
All my searches keep bring up how to include js in WordPress for the front end. I am looking to only include it if the page uses it.