Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callbacks are fired before scripts arrive... #17

Closed
adomado opened this issue Jul 9, 2011 · 7 comments
Closed

Callbacks are fired before scripts arrive... #17

adomado opened this issue Jul 9, 2011 · 7 comments

Comments

@adomado
Copy link

adomado commented Jul 9, 2011

<html>
  <head>
    <script>
    !function(a,b,c){function t(a,c){var e=b.createElement("script"),f=j;e.onload=e.onerror=e[o]=function(){e[m]&&!/^c|loade/.test(e[m])||f||(e.onload=e[o]=null,f=1,c())},e.async=0,e.src=a,d.insertBefore(e,d.firstChild)}function q(a,b){p(a,function(a){return!b(a)})}var d=b.getElementsByTagName("head")[0],e={},f={},g={},h={},i="string",j=!1,k="push",l="DOMContentLoaded",m="readyState",n="addEventListener",o="onreadystatechange",p=function(a,b){for(var c=0,d=a.length;c<d;++c)if(!b(a[c]))return j;return 1};!b[m]&&b[n]&&(b[n](l,function r(){b.removeEventListener(l,r,j),b[m]="complete"},j),b[m]="loading");var s=function(a,b,d){function o(){if(!--m){e[l]=1,j&&j();for(var a in g)p(a.split("|"),n)&&!q(g[a],n)&&(g[a]=[])}}function n(a){return a.call?a():e[a]}a=a[k]?a:[a];var i=b&&b.call,j=i?b:d,l=i?a.join(""):b,m=a.length;c(function(){q(a,function(a){h[a]?(l&&(f[l]=1),o()):(h[a]=1,l&&(f[l]=1),t(s.path?s.path+a+".js":a,o))})},0);return s};s.get=t,s.ready=function(a,b,c){a=a[k]?a:[a];var d=[];!q(a,function(a){e[a]||d[k](a)})&&p(a,function(a){return e[a]})?b():!function(a){g[a]=g[a]||[],g[a][k](b),c&&c(d)}(a.join("|"));return s};var u=a.$script;s.noConflict=function(){a.$script=u;return this},typeof module!="undefined"&&module.exports?module.exports=s:a.$script=s}(this,document,setTimeout)

      var cb = Math.random();
      var scripts = ["http://code.jquery.com/jquery-1.6.2.js?cb=" + cb];

      $script(scripts, function() {
        console.log(jQuery);
      });

      $script(scripts, function() {
        console.log(jQuery);
      });

      $script(scripts, function() {
        console.log(jQuery);
      });

      $script(scripts, function() {
        console.log(jQuery);
      });

      $script(scripts, function() {
        console.log(jQuery);
      });

    </script>
  </head>

  <body>
  </body>
</html>

Almost all callbacks fail in the above test case

@adomado
Copy link
Author

adomado commented Jul 9, 2011

I am using
Chrome - 13.0.782.41 beta

@adomado
Copy link
Author

adomado commented Jul 9, 2011

I am able to reproduce this bug in Chrome 12 & FF4, FF5.

@ded
Copy link
Owner

ded commented Jul 10, 2011

interesting... that's strange. i'll have a look

@ded
Copy link
Owner

ded commented Jul 10, 2011

i see what's going on. i'll have a patch for it soon

@ded ded closed this as completed in d8dc0f0 Jul 10, 2011
@adomado
Copy link
Author

adomado commented Jul 11, 2011

Hi Dustin,
Thanks alot for the quick fix.

However, with the new fix - in the above test case, the callback is fired just once - instead of being fired 5 times.

I think this should be a successful result of this test case...

  • jquery.js file is requested multiple times
  • $script loads it just once
  • $script fires every callback which was requesting this js file

Thanks,
Mayank

@ded
Copy link
Owner

ded commented Jul 11, 2011

yeah, i realized that afterward. i'm working on the next version of $scriptjs, so i'll make sure i include that functionality (could be quite useful)

@adomado
Copy link
Author

adomado commented Jul 12, 2011

Thanks a ton.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants