1.1.3 • Published 9 years ago

ajax-limited v1.1.3

Weekly downloads
9
License
See LICENSE
Repository
-
Last release
9 years ago

ajax-limited

Build Status Coverage Status


A rate-limited version of $.ajax with support for slow start on wakeup.

Installing

npm install --save ajax-limited

Usage

var $ = require('jquery');
var ajaxLimited = require('ajax-limited');

ajaxLimited.configure($, {
  bucketSize: 9,
  tokensPerInterval: 9,
  interval: 3000,
});

ajaxLimited.get({
  bucketSize: 2,
  tokensPerInterval: 2,
  interval: 3000,
});

Documentation

AjaxLimited

Manages the set of TokenBuckets limitting AJAX requests.

Params:

  • Object options Optional root TokenBucket options

.prototype.configure(target, options)

Configures rate limitting into an object.

Params:

.prototype.restore(target)

Restores the original ajax method on the configured targets or a target object.

Params:

Return:

  • Function originalAjax

.prototype.slowStart(options)

Receives initial options for each HTTP method (or all of them), modifies buckets so they start with them and slowly transitions rate limitting until the original rates are reached.

Params:

  • Object options

Example

ajaxLimited.slowStart({
  get: { // Slows down get to this rate
    bucketSize: 9,
    tokensPerInterval: 9
  },
  'put,patch,post,delete': { // Slows down post, put, patch, delete to this rate
    bucketSize: 9,
    tokensPerInterval: 0,
  },
  transitionTime: 9000, // Takes 9s to reach normal speed
  interval: 3000        // Updates speed every 3s
});
1.1.3

9 years ago

1.1.2

9 years ago

1.1.1

9 years ago