@T.J: This was a time saver on the scripts I have to load on my application as well as have learnt something new Many thanks ;-)
Regards Jason On 10/17/08, T.J. Crowder <[EMAIL PROTECTED]> wrote: > > For anyone coming to this thread later, there's now a (rough) how-to > on the unofficial wiki: > http://proto-scripty.wikidot.com/prototype:how-to-load-scripts-dynamically > > -- T.J. :-) > > On Oct 16, 11:11 am, "T.J. Crowder" <[EMAIL PROTECTED]> wrote: >> Hey Jason, >> >> [Call me T.J. :-)] >> >> Caveat: I have not had to do this in the wild, so there are sure to >> be better answers from others. I'll throw out an example that works >> in my limited testing (FF3, IE6, Safari 3, Opera 9): >> >> Loading the script dynamically from the statically-loaded script >> already on the page (in my example file I triggered this vi a button): >> * * * >> function go() >> { >> var head; >> var script; >> >> head = $$('head')[0]; >> if (head) >> { >> script = new Element('script', { type: 'text/javascript', src: >> 'dynamic.js' }); >> head.appendChild(script); >> }} >> >> * * * >> >> A function in the statically-loaded script that other scripts can use >> to announce themselves: >> * * * >> function hello(name) >> { >> alert('Script "' + name + '" loaded');} >> >> * * * >> >> My dynamic.js file: >> * * * >> hello('dynamic'); >> function coolness() >> { >> alert('Coolness!');} >> >> * * * * >> >> A modified version of hello() demonstrating that the dynamically- >> loaded script is accessible from the statically-loaded one: >> * * * * >> function hello(name) >> { >> alert('Script "' + name + '" loaded'); >> if (name == 'dynamic') >> { >> coolness(); >> }} >> >> * * * * >> >> Complete code on Pastie: >> HTML+static script:http://pastie.org/293753 >> dynamic.js:http://pastie.org/293754 >> >> Again, though, I wouldn't be at all surprised if there are subtlties >> and wrinkles that aren't dreamt of in my philosophy -- or at least not >> handled in this code. :-) >> -- >> T.J. Crowder >> tj / crowder software / com >> >> On Oct 16, 10:54 am, "jason maina" <[EMAIL PROTECTED]> wrote: >> >> > @Crowder: >> > This kind of amateurish, how will the script announce itself? >> > Kind of don't understand the concept >> >> > 2008/10/16 T.J. Crowder <[EMAIL PROTECTED]> >> >> > > > When the "script" element is inserted into the document body, does >> > > > the >> > > > currently-running script wait for the js file to be downloaded and >> > > executed? >> >> > > You'll want to try it out on the browsers you're targeting, but I tend >> > > to doubt it: All the code inserting the tag is doing is inserting the >> > > script element in the DOM, the browser does the rest and I'm guessing >> > > does it on its own thread(s). Probably best to have the script you're >> > > loading announce itself to the script loading it when it loads. Then >> > > you know it's there. >> > > -- >> > > T.J. Crowder >> > > tj / crowder software / com >> >> > > On Oct 15, 8:08 pm, "Hector Virgen" <[EMAIL PROTECTED]> wrote: >> > > > When the "script" element is inserted into the document body, does >> > > > the >> > > > currently-running script wait for the js file to be downloaded and >> > > executed? >> > > > Or does the js file download in the background while the current >> > > > script >> > > > finishes? >> > > > -Hector >> >> > > > 2008/10/15 buda <[EMAIL PROTECTED]> >> >> > > > > tere is a beautifull script ENSURE - try it >> >> > > > > On 15 окт, 14:16, "jason maina" <[EMAIL PROTECTED]> wrote: >> > > > > > Hi, >> >> > > > > > Is it possible to load script files only when they are needed. >> > > > > > In the application im currently making there are too many >> > > > > > script(js) >> > > > > files >> > > > > > loaded on the parent page yet in the entire life-cycle of the >> > > application >> > > > > > usage some tabs will not even be clicked hence the idea to only >> > > > > > load >> > > > > script >> > > > > > files when needed. >> >> > > > > > Thank you in advance. >> >> > > > > > - Jason >> >> > > > -- >> > > > -Hector >> >> > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---
