fetch-coalesce is a decorator that coalesces multiple equivalent fetch() calls into a single network request.
$> npm install fetch-coalesce --saveimport coalesce from 'fetch-coalesce';
const fetch = coalesce({ methods: ['GET', 'HEAD'] })(window.fetch);
fetch('/foo/bar');
fetch('/foo/bar');
// Only one network request is made.import coalesce from 'fetch-coalesce';- Function that accepts configuration and returns a fetch decorator
Function. - Parameters
- (
Object) config [optional]:- (
String[]) config.methods [optional]: HTTP methods (GET,PUT,POST, etc.) that should be coalesced. By default, all idempotent methods are coalesced.
- (
- (
- Returns
- (
Function): AfetchdecoratorFunction:- Parameters
- (
Function) fetch: The fetchFunctionto decorate. Should pretty much always bewindow.fetch.
- (
- Returns
- (
Function): The decorated fetchFunction. Call it just like you would callfetch().
- (
- Parameters
- (