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

Ready is triggered before the library is loaded #73

Open
nachitox opened this issue Aug 2, 2018 · 12 comments
Open

Ready is triggered before the library is loaded #73

nachitox opened this issue Aug 2, 2018 · 12 comments

Comments

@nachitox
Copy link

nachitox commented Aug 2, 2018

daterangepicker.js is loaded after moment, which loads after jquery.

load

Sometimes it works fine, but other times daterangepicker does not exists.

error

I'd prefer waiting a few ms than the library throwing an error.

What can I do?
Thank you

@amorey
Copy link
Member

amorey commented Aug 2, 2018

It looks like the screenshot got cut off so I can't see how jQuery is being loaded. Can you share the code that is causing the error?

@nachitox
Copy link
Author

nachitox commented Aug 3, 2018

jquery and moment are loaded using loadjs too

loadjs('https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js', 'jquery');
loadjs.ready('jquery', function() {
loadjs([REAL_PATH + 'moment/moment.min.js',], 'moment');
});

@amorey
Copy link
Member

amorey commented Aug 4, 2018

I don't know the internals of daterangepicker.js but it's possible that it has a dependency on DOMContentLoaded that is causing the intermittent failure. Have you tried wrapping your code with jQuery.ready()?

loadjs.ready('datepicker', function() {
  $.ready(function() {
    $('#datefrom').daterangepicker();
  });
});

In addition, your code appears to be loading jQuery, moment.js and daterangepicker.js sequentially. If you want to load them in parallel and execute them in order you can use async: false:

loadjs(['/path/to/jquery.js', '/path/to/moment.js', '/path/to/daterangepicker.js'], {
  async: false,
  success: function() {},
  error: function (pathsNotFound) {}
});

@saurabhnanda
Copy link

I'm seeing similar behaviour.

@amorey
Copy link
Member

amorey commented Jul 20, 2020

Did you try the suggestions above? #73 (comment)

@DoubleCorner
Copy link

I'm seeing similar behaviour also. Miraculously, there is no problem in the my local PC, but there are occasional errors on the line

@DoubleCorner
Copy link

DoubleCorner commented Mar 26, 2021

addtionally, I have set the async is false
I think the problem maybe is here.As long as async exists, whether it is true or false, it means asynchronous
image

image
if(async || async === undefined) e.async = true ???

@amorey
Copy link
Member

amorey commented Mar 27, 2021

The javascript object accepts false as a value so if you set the async property to false then the scripts will not be loaded asynchronously (https://www.w3schools.com/jsref/prop_script_async.asp).

Can you share the problematic code so I can take a closer look at it?

@DoubleCorner
Copy link

DoubleCorner commented Mar 29, 2021

like it

if(hasLoad) {
    loadjs(['/path/to/map.js'], 'map' {
      async: false
    });
    hasLoad = true;
}
loadjs.ready(['map'],()=>{
 map.refresh(); // sometime map is undefined
})

In particular, it will be called twice during initialization, first is in 'componentDidMount', second is in 'componentWillReceiveProps'

@amorey
Copy link
Member

amorey commented Mar 29, 2021

Without knowing what map.js does internally I can't tell what the problem is. There could be a dependency on DOMContentLoaded that is causing an intermittent failure as described above. Can you provide a working code snippet that I can run? If you can provide a working HTML file that demonstrates the problem that would make it easier to debug.

@amorey
Copy link
Member

amorey commented Mar 15, 2024

@DoubleCorner I got an email notification that you left a new message but now I can't see the message. Did you figure out the problem?

@DoubleCorner
Copy link

DoubleCorner commented Mar 15, 2024

@amorey no, I will try again. if I figure out, I will write my solution. Thanks for your reply.

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

4 participants