On Jan 27, 2008 10:02 PM, Justin Perkins <[EMAIL PROTECTED]> wrote:

>
> On Jan 27, 2008 7:09 PM, Nathan Nobbe <[EMAIL PROTECTED]> wrote:
> > im not sure why you want to retrieve the remote script once the page has
> > loaded.
>
> It's actually a very nice way to include external scripts, since the
> loading of a script (with src) has an effect on page load times, which
> impacts tasks that run on page load and also visible to the user by
> way of the browser's progress indicator.
>
> You can create script nodes on the fly, with normal DOM-node creating
> code and it works well in Firefox and IE6/7. I have not tested other
> browsers.
>
> This is the basic idea: http://pastie.textmate.org/144194
>
> Note that the first thing that code does is look for a script include
> already on the page that has included the same script, and if it is
> found, then it is removed. This may be overkill, but is done to
> prevent caching problems. If the same function that includes the
> script is called multiple times, and you're expecting the script to be
> refreshed, then you may want to append some type of no-cache parameter
> (a time stamp) onto the URL, such as:
>
> // do this just before the call to setAttribute('src', src)
> src = ( src.match( /\?/ ) ? src + '&' : src + '?' ) + ( nocache ?
> 'nocache=' + new Date().getTime() + '&' : '' );
>
> This little snippet has worked out very well for me, especially when
> requesting external scripts that may take a while to load.
>
> Have a great night.


if you want a good model for dynamically loading scripts via ajax with the
protoype framework, take a look at scriptacuolus.js, they have the exact
mechanism you are looking for in place already.
also, per the construction of dom nodes dynamically, take a look at
builder.js
also bundled in the scriptaculous library.

-nathan

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" 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/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to