Implementation of Offline-js with some improvements
Because Offline-js has some bugs and inconsistencies
- Promises support (axios)
- localStorage support
- Save ALL the failed requests, not just the last one
- Requests keep saved even if user try to refresh the page when offline
- Send ALL failed requests when connection is up again
- No need configuration
- Node / npm
npm install --save handle-failed-requests-js
import Request from 'handle-failed-requests-js';
Request.send({
method: 'put',
data: data,
url: '/'
}).then(res => {
console.log(res);
});
<script src="handle-requests.min.js"></script>
var req = new Request();
// default method is post
req.send('/', data).then(function(res) {
console.log(res);
});
// or
req
.send({
method: 'put',
data: data,
url: '/'
})
.then(function(res) {
console.log(res);
});
See Axios documentation for requests options