Skip to content
Wraps your AJAX save logic in a cozy, edge-case-preventing blanket.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

autosaver status bower

autosaver wraps your AJAX save logic in a cozy, edge-case-preventing blanket.


var autosaver = new Autosaver({
  fn: function (done) {
      url: '/your/endpoint',
      data: { your: 'data' },
      complete: function(){

// autosaver debounces your AJAX calls so that only one request is made
// on the trailing edge. In this example, the AJAX request will be made
// *2000 milliseconds after* the last call to saveLater().

// autosaver also allows for calling .saveNow(). In this example, the AJAX
// request will be sent immediately after the call to .saveNow().

However, autosaver shines by handling the edge cases for you. By using autosaver, you ensure that the client is only ever sending 1 request at a time to your server, otherwise you might run into race conditions where the user's data will be overwritten by conflicting saves.



Queues the call to your save function until have passed. If the function has already been queued for more than @options.max milliseconds, calls it immediately.


Calls the save function immediately. If there is already a save in-flight, waits until after that save is complete to start another save.


If there are unsycned changes, calls the save function and then cb. If there are no changes, calls cb immediately. Useful to ensure all changes are saved before a user leaves the page, for example.


Returns true if there is a save queued, otherwise returns false.


Exponentially increases the save interval. Useful if the server returns an error code so that you don't flood it with requests.


Resets the save interval.


key description default
fn function signature: function(done){} -
ms The number of milliseconds to delay calls to fn. (Referred to as wait by most debounce functions.) 2000
max The maximum time fn is allowed to be delayed before it is invoked. Set to 0 to always wait. 8000



You can’t perform that action at this time.