Skip to content

Commit

Permalink
#24: Prevent canceled requests from fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Ángel Pérez committed Aug 14, 2014
1 parent 53d38dd commit 479b44e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions jquery.smoothState.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,10 @@
}

setTimeout(function () {
responses[cache[url].status]();
// Might of been canceled, better check!
if(cache.hasOwnProperty(url)){
responses[cache[url].status]();
}
}, 10);
},

Expand Down Expand Up @@ -427,14 +430,16 @@
// Don't fetch we have the content already
if(cache.hasOwnProperty(url)) return;

cache = utility.clearIfOverCapacity(cache, options.pageCacheSize);

cache[url] = { status: "fetching" };

var requestUrl = options.alterRequestUrl(url) || url,
request = $.ajax(requestUrl);

// Store contents in cache variable if successful
request.success(function (html) {
// Clear cache varible if it's getting too big
cache = utility.clearIfOverCapacity(cache, options.pageCacheSize);
utility.storePageIn(cache, url, html);
$container.data('smoothState').cache = cache;
});
Expand Down
2 changes: 1 addition & 1 deletion smoothState.jquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"ui",
"ajaxify"
],
"version": "0.4.1",
"version": "0.5.0",
"author": {
"name": "Miguel Angel Perez",
"url": "http://miguel-perez.com/"
Expand Down

0 comments on commit 479b44e

Please sign in to comment.