README
fetch-coalesce
fetch-coalesce
is a decorator that coalesces multiple equivalent fetch()
calls into a single network request.
Install
Coalesces multiple calls to fetch() for the same URL into a single network request.
<script type="module">
import fetchCoalesce from 'https://cdn.skypack.dev/fetch-coalesce';
</script>
fetch-coalesce
is a decorator that coalesces multiple equivalent fetch()
calls into a single network request.
gt; npm install fetch-coalesce --save
import 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
.Object
) config [optional]:String[]
) config.methods [optional]: HTTP methods (GET
, PUT
, POST
, etc.) that should be coalesced. By default, all idempotent methods are coalesced.Function
): A fetch
decorator Function
:Function
) fetch: The fetch Function
to decorate. Should pretty much always be window.fetch
.Function
): The decorated fetch Function
. Call it just like you would call fetch()
.