Pure Javascript Ajax queuing for efficient handling of frontend requests.
const queue = new Queue([config]);
queue.add([request]);
The config object is not required
| Name | Description | Type | Default |
|---|---|---|---|
| success | The callback for all successful ajax requests processed by this queue | function | Dispatch a Queue:requestCompleted event |
| error | The callback for all unsuccessful ajax requests processed by this queue | function | Dispatch a Queue:requestFailed event |
| completedAllRequestsEvent | The event type that will be dispatched once all requests have finished | string | Queue:requestsCompleted |
| completedRequestEvent | The event type that will be dispatched after each request is finished | string | Queue:requestCompleted |
| failedRequestEvent | The event type that will be dispatched after a request has failed | string | Queue:requestFailed |
| requestStartedEvent | The event type that will be dispatched after each request has started | string | Queue:requestStarted |
| errorEvent | The event type that will be dispatched after Q has thrown an error | string | Queue:error |
Adds a request to the currently running queue, this will cause the queue to process each item, one at a time until all requests have been resolved.
const queue = new Queue()
// Build the ajax request
const request = {
url: '/cart/add.js',
data: item,
success: options.success,
error: options.error
}
// Add the request to the ajax request queue
this.queue.add(request)
})
Options:
'', 'arraybuffer', 'blob', 'document', 'json', 'text'
