explicitely prevent caching of XHR GET requests

This commit is contained in:
Thibault Duplessis 2015-01-04 19:51:10 +01:00
parent 44e12b1ac2
commit bbfc06b1ee
6 changed files with 49 additions and 17 deletions

View file

@ -622,6 +622,7 @@ lichess.storage = {
$('#message_notifications_tag').on('click', function() {
$.ajax({
url: $(this).data('href'),
cache: false,
success: function(html) {
$('#message_notifications_display').html(html)
.find('a.mark_as_read').click(function() {
@ -680,6 +681,7 @@ lichess.storage = {
var $themepicker = $('#themepicker');
$.ajax({
url: $(this).data('url'),
cache: false,
success: function(html) {
$themepicker.append(html);
var $body = $('body');
@ -902,6 +904,7 @@ lichess.storage = {
langs = acceptLanguages.split(',');
$.ajax({
url: $links.data('url'),
cache: false,
success: function(list) {
$links.prepend(list.map(function(lang) {
var klass = $.fp.contains(langs, lang[0]) ? 'class="accepted"' : '';
@ -1102,10 +1105,14 @@ lichess.storage = {
},
end: function() {
var url = (data.tv ? cfg.routes.Tv.side : cfg.routes.Round.sideWatcher)(data.game.id, data.player.color).url;
$.get(url, function(html) {
$('#site_header div.side').replaceWith(html);
$('body').trigger('lichess.content_loaded');
startTournamentClock();
$.ajax({
url: url,
cache: false,
success: function(html) {
$('#site_header div.side').replaceWith(html);
$('body').trigger('lichess.content_loaded');
startTournamentClock();
}
});
},
checkCount: function(e) {
@ -1528,6 +1535,7 @@ lichess.storage = {
reload_timeline: function() {
$.ajax({
url: $("#timeline").data('href'),
cache: false,
success: function(html) {
$('#timeline').html(html);
$('body').trigger('lichess.content_loaded');
@ -1551,7 +1559,9 @@ lichess.storage = {
},
reload_forum: function() {
setTimeout(function() {
$.ajax($newposts.data('url'), {
$.ajax({
url: $newposts.data('url'),
cache: false,
success: function(data) {
$newposts.find('ol').html(data).end().scrollTop(0);
$('body').trigger('lichess.content_loaded');
@ -1841,6 +1851,7 @@ lichess.storage = {
$('.lichess_overboard').remove();
$.ajax({
url: $(this).attr('href'),
cache: false,
success: function(html) {
$('.lichess_overboard').remove();
$('#hooks_wrap').prepend(html);
@ -1917,6 +1928,7 @@ lichess.storage = {
function reload() {
$.ajax({
url: $wrap.data('href'),
cache: false,
success: function(html) {
var $tour = $(html);
if ($wrap.find('table.standing').length) {

View file

@ -70,10 +70,14 @@ module.exports = {
return m('div.hook_filter', {
config: function(el, isUpdate, ctx) {
if (ctx.loaded) return;
$.get('/setup/filter', function(html) {
el.innerHTML = html;
ctx.loaded = true;
initialize(ctrl, el);
$.ajax({
url: '/setup/filter',
cache: false,
success: function(html) {
el.innerHTML = html;
ctx.loaded = true;
initialize(ctrl, el);
}
});
}
});

View file

@ -5,18 +5,22 @@ var xhrConfig = function(xhr) {
xhr.setRequestHeader('Accept', 'application/vnd.lichess.v1+json');
}
function uncache(url) {
return url + '?_=' + new Date().getTime();
}
module.exports = {
seeks: function() {
return m.request({
method: 'GET',
url: '/lobby/seeks',
url: uncache('/lobby/seeks'),
config: xhrConfig
});
},
nowPlaying: function() {
return m.request({
method: 'GET',
url: '/lobby/playing',
url: uncache('/lobby/playing'),
config: xhrConfig
});
}

View file

@ -273,8 +273,12 @@ function renderHistory(ctrl) {
var hash = ctrl.data.user.history.join('');
if (hash == context.hash) return;
context.hash = hash;
$.get('/training/history', function(html) {
el.innerHTML = html;
$.ajax({
url: '/training/history',
cache: false,
success: function(html) {
el.innerHTML = html;
}
});
}
});

View file

@ -10,6 +10,10 @@ function showLoading(ctrl) {
m.redraw();
}
function uncache(url) {
return url + '?_=' + new Date().getTime();
}
function attempt(ctrl, win) {
showLoading(ctrl);
m.request({
@ -44,7 +48,7 @@ function retry(ctrl) {
showLoading(ctrl);
m.request({
method: 'GET',
url: ctrl.router.Puzzle.load(ctrl.data.puzzle.id).url,
url: uncache(ctrl.router.Puzzle.load(ctrl.data.puzzle.id).url),
config: xhrConfig
}).then(ctrl.reload);
}
@ -65,7 +69,7 @@ function newPuzzle(ctrl) {
showLoading(ctrl);
m.request({
method: 'GET',
url: '/training/new',
url: uncache('/training/new'),
config: xhrConfig
}).then(ctrl.reload);
}

View file

@ -5,12 +5,16 @@ var xhrConfig = function(xhr) {
xhr.setRequestHeader('Accept', 'application/vnd.lichess.v1+json');
}
function uncache(url) {
return url + '?_=' + new Date().getTime();
}
function reload(ctrl) {
ctrl.vm.reloading = true;
m.redraw();
var req = m.request({
method: 'GET',
url: ctrl.data.url.round,
url: uncache(ctrl.data.url.round),
config: xhrConfig
});
req.then(function() {
@ -24,7 +28,7 @@ function reload(ctrl) {
function next(ctrl) {
return m.request({
method: 'GET',
url: ctrl.router.Round.next(ctrl.data.game.id).url,
url: uncache(ctrl.router.Round.next(ctrl.data.game.id).url),
config: xhrConfig
});
}