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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.