#460 ✓resolved
jrochkind

Dynamic loading of Prototype does not work

Reported by jrochkind | November 21st, 2008 @ 06:10 PM | in 1.7

So in Prototype 1.6, it seems no longer possible to dynamically load the Prototype library. In my previous code using Prototype 1.3, this worked fine. (I've jumped right from 1.3 to 1.6)

This may be related to this ticket in the old system, but I think it's actually a different problem, for one thing I was noticing the problem in Firefox, not IE. http://dev.rubyonrails.org/ticke...

tfluehr in the IRC channel helped me identify the fact that 1.6 uses document.write to add dom.onloaded functionality as the culprit.

Commenting out this functionality (prototype.js line 4028) fixes things so I can load Prototype dynamically again. So I've done that.

This is dangerous of course if Prototype or Sciptaculous count on dom.onloaded functionality in any internal code. I don't use the new dom.onloaded functionality myself in any of my code.

I'm not sure what if anything should be done in Prototype about this? Being able to load Prototype dynamically is a very useful feature. Maybe there's some way to add dom.onloaded functionality without a document.write? A comment in that old ticket suggests that jQuery pulls that off.

Or maybe there could be some way for a developer to choose if they want Prototype with dom.onloaded functionality, or instead with dynamic loading ability? But I can't think of any good way to support that.

At a minimum, I would suggest that Prototype/Scriptaculous developers avoid using dom.onloaded in any prototype/scriptaculous internal code, to at least make it possible for someone like me to patch like this, to restore dynamic loading at the expense of dom.onloaded.

For reference, here is the code I am using to dynamically load prototype. My source html loads an external .js of my own, which then says:


  if( typeof(window.Prototype) == "undefined") {
    document.write('<script type="text/javascript" src="'+umlaut_base+'/javascripts/prototype.js"><\/script>');
    //var script = document.createElement('script');
    //script.setAttribute('type','text/javascript');
    //script.setAttribute('src',umlaut_base+'/javascripts/prototype.js');

  }

Firefox was complaining with a weird error about XML that didn't make any sense. After commenting out the dom.onload functionality, dynamic loading of Prototype 1.6 seems to work fine in IE6, IE7, and FF3.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

Pages