I'm developing a web application that relies on AJAX technology to load the pages. Each page has an associated JavaScript file. When a new page is loaded the previous JavaScript file is removed but the code still remains in the DOM.
What's the best approach to remove the objects of the previous JavaScript file from the DOM?
I've googled about this subject and the right answer appears to be the use of the module pattern but this implies a major refactoring of the project.