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

Support for Various Retry options #49

Open
sckimynwa opened this issue Dec 6, 2022 · 4 comments
Open

Support for Various Retry options #49

sckimynwa opened this issue Dec 6, 2022 · 4 comments

Comments

@sckimynwa
Copy link

sckimynwa commented Dec 6, 2022

Summary

Hi, I'm recently using this plugin to my project.
Thanks to this plugin, it reduces my chunk load failed error a lot.
as a user of this plugin, I think it would be nice if you provide some various retry options like exponential backoff

For Example,

plugins: [
  new RetryChunkLoadPlugin({
    // optional stringified function to get the cache busting query string appended to the script src
    // if not set will default to appending the string `?cache-bust=true`
    cacheBust: `function() {
      return Date.now();
    }`,
    // optional value to set the amount of time in milliseconds before trying to load the chunk again. Default is 0
    // if string, value must be code to generate a delay value. Receives retryCount as argument 
    // e.g. `function(retryAttempt) { return retryAttempt * 1000 }`
    retryDelay: 3000,
    // optional value to set the maximum number of retries to load the chunk. Default is 1
    maxRetries: 5,
    // retry delay options
    // my suggestion
    retryType : 'linear' | 'exponential',
    retryFunc : SOME FUNCTION TYPE,
    // optional list of chunks to which retry script should be injected
    // if not set will add retry script to all chunks that have webpack script loading
    chunks: ['chunkName'],
    // optional code to be executed in the browser context if after all retries chunk is not loaded.
    // if not set - nothing will happen and error will be returned to the chunk loader.
    lastResortScript: "window.location.href='/500.html';",
  }),
];

Thank you in advance.

Reference

@sckimynwa
Copy link
Author

Or, It would also be nice to support custom delay functions for user I think 🤔

@bluthen
Copy link

bluthen commented Dec 7, 2022

// optional value to set the amount of time in milliseconds before trying to load the chunk again. Default is 0
    // if string, value must be code to generate a delay value. Receives retryCount as argument 
    // e.g. `function(retryAttempt) { return retryAttempt * 1000 }`

It looks like you can give retryDelay a function. I just use a regular delay, but it is in the readme.

Edit: Looks like this was a version 1 feature not a version 2 feature. So could be a good addition to version 2/3

@shridhar-purandare
Copy link

A way to log failed chunk load URLs would be good to debug failed chunk-loading retries.

@bluthen
Copy link

bluthen commented Jan 9, 2023

I know you can load chunks different ways, but I often handle it where I load. I use specific chunks. I try to keep the chunks related to sections, especially rarely used ones that only get loaded if they are needed.

try {
   mymodules = await import 'somemodule';
} catch(err) { logger.error(err); throw err;}

And I use catchall.
https://developer.mozilla.org/en-US/docs/Web/API/Window/error_event

Unhandled errors should be going to console anyway, but if you have like an external logger might be good idea to have that catchall anyway.

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

3 participants