I´ve a page structure with a main area. Every page of the site is loaded in that area using ajax. To properly load the scripts that the new pages is goint to use, I use the next code taken from http://www.hunlock.com/blogs/Howto_Dynamically_Insert_Javascript_And_CSS
var headID = document.getElementsByTagName("head")[0];
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = 'somescript.js';
newScript.id = "dynamicScript";
headID.appendChild(newScript);
My question is, What happens when the user calls the page several times, all the scritps are loaded once and again? That will cause memory problems in the future?
I tried to remove the script element before creating the new one:
var headScriptfunctions = document.getElementById("dynamicScript");
if (headScriptfunctions != null){
head.removeChild(headScriptfunctions);
}
And the script is deleted from the head, but anyway, the scripts is still alive because I can call it. I think to use jquery getScript function, but i don´t know how it works when called the same script serveral times.