Hi,
I've been playing with AJAX and trying to dynamically load JS, I then tried to simply alter the src of a script tag, which works fine, however..
If you have a function called test1() in script test1.js, you load it by default on the page.
In that function it changes the source of the script tag to test2.js and then fires test2() it works fine.
However, you can still call test1() even though the source of the script has been altered.
In fact I've even changed the source to = '' , and both functions are still available to be called.
Therefore changing the src of a JS tag doesn't change the functions available to the browser, but must add them to some repository.
As it behaves in this manner, you might as well load all JS files at the start.
I'm trying to find a way to load the JS in small chunks and only use up resources to store the JS required for the section of the application they are currently using.
Is this possible?
I was even thinking of creating an object and changing it's source where the methods were stored within the object.
would creating a class with methods and assigning it to an object be the only way to achieve what I want or is there a way to clear the JS store?
Cheers,
1DMF.
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
I've been playing with AJAX and trying to dynamically load JS, I then tried to simply alter the src of a script tag, which works fine, however..
If you have a function called test1() in script test1.js, you load it by default on the page.
In that function it changes the source of the script tag to test2.js and then fires test2() it works fine.
However, you can still call test1() even though the source of the script has been altered.
In fact I've even changed the source to = '' , and both functions are still available to be called.
Therefore changing the src of a JS tag doesn't change the functions available to the browser, but must add them to some repository.
As it behaves in this manner, you might as well load all JS files at the start.
I'm trying to find a way to load the JS in small chunks and only use up resources to store the JS required for the section of the application they are currently using.
Is this possible?
I was even thinking of creating an object and changing it's source where the methods were stored within the object.
would creating a class with methods and assigning it to an object be the only way to achieve what I want or is there a way to clear the JS store?
Cheers,
1DMF.
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!