I have a PHP script that includes a .JS file. The PHP file makes a jquery call to an external functions.php
file which requires the same .JS file, however, with it being a separate file, I have to include it again inside functions.php
. If I do this, it breaks the first include, but the 2nd include works. If I remove the include from the external file, the script doesn't work, but everything in the original file does.
Is there a way to include a JS file in the external file without calling it again? Can it just call from the first include?
Included as:
<script type="text/javascript" src="js/scripts.min.js"></script>
Using php's include_once
should resolve your problem. This function ensures that the given file will only be included once.