So, I am writing an application using RequireJS and Socket.io, which checks if socket.io is available, and then, when connected, loads the application. In the case where socket.io is ever temporarily omitted, I would like the request to participate in the resource to be several times until it is available, and then continue to initialize the application.
Unfortunately (or maybe fortunately?), There seems to be some kind of caching mechanism requiring it to register scripts for scripts that don't load, so if you execute setTimeout in the error callback that the function returns socket, require will continue to throw errors even when the resource becomes available.
Is this an oversight or is there a reason to keep this error? More importantly, is there a workaround that would require relaying?
Here is an example of what I tried:
function initialize() { require(['socketio', function(io) { io.connect('http://localhost'); app._bootstrap(); }, function(err) { console.log(err); setTimeout(initialize, 10000); }); }
source share