Basically I have 4 views in my page (4 different sections in a single HTML page), I am hiding and showing the required views based on the button click.
I have 4 separate JS file for these 4 views. Based on the page user is in I am loading the JS page using the command
//Page1
if (current_page == 'Page1') {
$.getScript("/js/Page1.js");
}
I want to remove the all unused JS (JS which are used for other pages) when user navigates to 2nd page and only Page2.js
should be loaded, Currently when user navigates to 2nd page (Page1 to Page2) both Page1.js
and Page2.js
are being loaded.
$.getScript
can load the JS but is there a command or way to remove the JS from page and load the JS file dynamically?