unemployment Posted February 16, 2011 Share Posted February 16, 2011 I currently add in each pages JS in my site by using a variable Example: if (file_exists("./assets/js/pages/${page}.js")) { echo "<script type=\"text/javascript\" src=\"./assets/js/pages/${page}.js\"></script>"; } If I'm on list.php for instance it would load the list JavaScript, but based on which if statement result is executed, some of the JavaScript is not need. How can I still use this format but split up my JavaScript functions to correlate with the correct page loads. I'm tired of looking at these firebug errors. Link to comment https://forums.phpfreaks.com/topic/227903-add-in-js-with-php/ Share on other sites More sharing options...
BlueSkyIS Posted February 16, 2011 Share Posted February 16, 2011 either split the js into different files or use PHP if/then around the js functions and load them as needed. the second option will require that the JS is in the .php file OR the .js file is changed to a .php file so that it is executed by the server before being sent to the browser. Link to comment https://forums.phpfreaks.com/topic/227903-add-in-js-with-php/#findComment-1175181 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.