kubetail-org / loadjs

A tiny async loader / dependency manager for modern browsers (899 bytes)
MIT License
2.58k stars 150 forks source link

Retry loading a file #27

Closed rarkins closed 7 years ago

rarkins commented 7 years ago

I've been logging error callbacks from loadjs for the past 5 weeks. My observations are:

This leads me to believe that in some of these cases, retrying failed file loads might actually work. Although I could probably write a wrapper around this, would you support the concept of retries in the library itself?

rarkins commented 7 years ago

Cc @amorey

amorey commented 7 years ago

@rarkins Nice work! It's useful to get a sense of why the errors are actually occurring. I think we can add a numRetries option without adding too many bytes to the script. Do you want to take a stab at it?

rarkins commented 7 years ago

@amorey yes, I'll take a look at the source code

amorey commented 7 years ago

@rarkins I added a numRetries option to loadjs in v3.1.0:

loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', {
  success: function() { /* foo.js & bar.js loaded */ },
  error: function(pathsNotFound) { /* at least one path didn't load */ },
  numRetries: 2
});

Let me know if you run into any issues using the feature.

rarkins commented 7 years ago

@amorey thanks for adding this. Can you tell me if my understanding is correct?

?

amorey commented 7 years ago

@rarkins That's correct:

Initially I had chosen the name numTries but I thought your suggestion of numRetries made the retry behavior more explicit. Let me know if you think numTries would be better or if you have any other suggestions!

rarkins commented 7 years ago

@amorey I think that numRetries is fine - I was just wanting to double check we had the same understanding of terminology

rarkins commented 7 years ago

I tested this in development and experimented with blocking dependencies using a browser plugin. I verified:

I couldn't work out a way to truly simulate a bad network and block a dependency 1 or 2 times before allowing it to succeed.

Anyway, I will push this to production shortly and let you know if I can observe anything after a while. Lately it's been pretty good with < 1% of users reporting network errors (assuming such reports to my analytics aren't lost or blocked!).

Thanks again for solving this.

amorey commented 7 years ago

Great! Thanks for checking the code with the browser plugin. Let me know if the new code decreases the number of network errors you're seeing.