fetch-once

Ensure requests are only made once no matter how many times your application calls them, support custom cache lengths.

Usage no npm install needed!

<script type="module">
  import fetchOnce from 'https://cdn.skypack.dev/fetch-once';
</script>

README

Fetch-Once Circle CI

Ensure requests are only made once no matter how many times your application calls them, support custom cache lengths.

options

  • Supports all request options
{
    cache: true|false|int, // default: true
    successHandler: fn // For heavy processing of response only performed once
}

Example usage


// pendingRequests (singleton)
var requests = {};

// Component1.js
var fetchOnce = require('fetch-once');

fetchOnce(requests, {
    url: 'http://google.com'
}).then(function (data) {
    // use data in render
});

// Component2.js
var fetchOnce = require('fetch-once');

fetchOnce(requests, {
    url: 'http://google.com'
}).then(function (data) {
    // use data in render
});