jquery getScript

guest2013-1

guest
Joined
Aug 22, 2003
Messages
19,800
Does this function fetch the javascript EACH time you call it, or is there some check you can perform to see if the js file loaded dynamically already and there's no need to fetch it again?
 

Darko

Senior Member
Joined
Jul 9, 2008
Messages
627
This calls the javascript function when you need it. Every time. You need to use it everytime you want to use that function as well.
 

guest2013-1

guest
Joined
Aug 22, 2003
Messages
19,800
Not sure I understand what you mean. Because let's say I have:

a href="#" onclick="test()"

test() is then in a function in an outside javascript not initially loaded in the page

I then call (for example) example.js in getScript on document.ready

So now I can click test() as much as I want to it will fire that function.

Of course, when you reload the page, you'd need to load the js file with getScript again

However.... what if you use $.load to load HTML into a div, displaying a specific bit of html, and in that html there's a getScript function that fires to get javascript needed to run functions in that piece of html.

Because the page didn't reload, technically the browser still has access to whatever script it loaded when $.load was used correct? in that case, there is no need to re-dynamically-get and load the js again,because it's already at the browser.... erf... my head hurts
 

guest2013-1

guest
Joined
Aug 22, 2003
Messages
19,800
If you load something using the .load function in jquery into a div. And that html you loaded calls a getScript loading a javascript dynamically. And none of your application refreshes the screen again (meaning, you only load portions of the site through the navigation, with no back button etc, everything works through ajax)

you only need to load the javascript once....

Now to figure out if that object is loaded or not so I don't have to call the getScript...
 
Top