Open nachitox opened 6 years ago
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?
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');
});
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) {}
});
I'm seeing similar behaviour.
Did you try the suggestions above? https://github.com/muicss/loadjs/issues/73#issuecomment-410404667
I'm seeing similar behaviour also. Miraculously, there is no problem in the my local PC, but there are occasional errors on the line
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
if(async || async === undefined) e.async = true ???
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?
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'
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.
@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?
@amorey no, I will try again. if I figure out, I will write my solution. Thanks for your reply.
daterangepicker.js is loaded after moment, which loads after jquery.
Sometimes it works fine, but other times daterangepicker does not exists.
I'd prefer waiting a few ms than the library throwing an error.
What can I do? Thank you