I have research about an issue and could not find a solution for it through normal JavaScript techniques (maybe there is but I did not find any).
The thing is, my application loads ( inserts) JavaScript files whenever the user loads a section of the system. The problem comes when I try to unload ( removal) one.
I've noticed that if I load section A (which loads script A'), then load section B (which loads script B'), and then load section A again, the code in script A' does not run again, thus every event registration in there doesn't get performed, which I do want to happen. (Maybe some extra kind of cleaning is required that I am not aware of?)
Any ideas? If what I just said makes any sense...
An example:
1- User enters Section 'Products'
2- Both the UI and JavaScript file associated to 'Products' get loaded
2.1- Products.js is now inserted in the <head>
2.2- Products.js code gets parsed and executed
3- User enters Section 'Clients'
3.1 - Products.js reference is removed from the <head>
4- Both the UI and JavaScript file associated to 'Clients' get loaded
4.1- Clients.js is now inserted in the <head>
4.2- Clients.js code gets parsed and executed
5- User enters Section 'Products'
5.1 - Clients.js reference is removed from the <head>
6- Both the UI and JavaScript file associated to 'Products' get loaded
6.1- Products.js is now inserted in the <head>
6.2- Products.js code **DOES NOT** get parsed nor executed
Thanks in advance.
P.S.: No framework is being used for this part of the application.