Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/remy/memfetch
Caches fetch responses and promises for faster development
https://github.com/remy/memfetch
Last synced: 6 days ago
JSON representation
Caches fetch responses and promises for faster development
- Host: GitHub
- URL: https://github.com/remy/memfetch
- Owner: remy
- Created: 2018-12-21T21:28:53.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-10T13:04:35.000Z (over 4 years ago)
- Last Synced: 2024-10-02T08:08:40.466Z (about 1 month ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 46
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# memfetch
An unobtrusive development library for caching and returning fetch requests.
The concept is that the library is included for development to reduce external API requests (particularly around rate-limiting) and to reduce latency, whilst making it easy to remove the library when ready for development.
## Usage
You can include the library via an npm install, or I'd recommend a simple script include:
```html
```
As long the script is before your own code, all requests using `fetch` will be cached and served via IndexedDB subsequently.
## Only caching specific URLs
Since memfetch doesn't play nicely with things like Hot Module Reload, you can specify to only allow memfetch to handle matching URLs. To do so, include a string fragment in the query string of the script include. This method (below) will cache any URL that includes `api` in the string:
```html
```
## Clearing / resetting the cache
The memfetch wrapper also provides a property called `seed`. Upon setting the value, or changing it (between sessions) will completely empty the cache.
## License
- [MIT](https://rem.mit-license.org)