Cache the versions response in local storage to reduce network activity
[ci-skip]
This commit is contained in:
@@ -233,6 +233,21 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var ls2 = {
|
||||||
|
save : function(key, jsonData, expirationMS) {
|
||||||
|
if (typeof (Storage) == "undefined") { return false; }
|
||||||
|
var record = {value: JSON.stringify(jsonData), timestamp: new Date().getTime()/1000 + expirationMS}
|
||||||
|
localStorage.setItem(key, JSON.stringify(record));
|
||||||
|
return jsonData;
|
||||||
|
},
|
||||||
|
load : function(key) {
|
||||||
|
if (typeof (Storage) == "undefined") { return false; }
|
||||||
|
var record = JSON.parse(localStorage.getItem(key));
|
||||||
|
if (!record){return false;}
|
||||||
|
return (new Date().getTime()/1000 < record.timestamp && JSON.parse(record.value));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Array.prototype.forEach.call(blockquotes, function (el, i) {
|
Array.prototype.forEach.call(blockquotes, function (el, i) {
|
||||||
if (el.innerHTML.indexOf('New as of') !== -1) {
|
if (el.innerHTML.indexOf('New as of') !== -1) {
|
||||||
addClass(el, 'new-as-of');
|
addClass(el, 'new-as-of');
|
||||||
@@ -280,7 +295,6 @@
|
|||||||
ref = 'dokku';
|
ref = 'dokku';
|
||||||
versionName = 'master';
|
versionName = 'master';
|
||||||
}
|
}
|
||||||
console.log(currentVersion, versionName);
|
|
||||||
|
|
||||||
a.setAttribute('href', "/" + ref + "/" + localPath);
|
a.setAttribute('href', "/" + ref + "/" + localPath);
|
||||||
a.appendChild(document.createTextNode(versionName));
|
a.appendChild(document.createTextNode(versionName));
|
||||||
@@ -294,34 +308,45 @@
|
|||||||
versionList.appendChild(dd);
|
versionList.appendChild(dd);
|
||||||
};
|
};
|
||||||
|
|
||||||
var request = new XMLHttpRequest();
|
var processVersions = function(data) {
|
||||||
request.open('GET', '/dokku/assets/versions.json', true);
|
var versions = [];
|
||||||
request.setRequestHeader("Cache-Control", "no-cache, no-store");
|
for (var key in data['max-versions']) {
|
||||||
|
if (!data['max-versions'].hasOwnProperty(key)) {
|
||||||
request.onload = function() {
|
continue;
|
||||||
if (request.status >= 200 && request.status < 400) {
|
|
||||||
versions = []
|
|
||||||
var data = JSON.parse(request.responseText);
|
|
||||||
for (var key in data['max-versions']) {
|
|
||||||
if (!data['max-versions'].hasOwnProperty(key)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
versions = parseVersions(data['max-versions'][key], versions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addVersionLink('master');
|
versions = parseVersions(data['max-versions'][key], versions);
|
||||||
Array.prototype.forEach.call(versions, function (version, i) {
|
|
||||||
addVersionLink(version);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addVersionLink('master');
|
||||||
|
Array.prototype.forEach.call(versions, function (version, i) {
|
||||||
|
addVersionLink(version);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
request.onerror = function() {
|
data = ls2.load('max-versions');
|
||||||
// There was a connection error of some sort
|
if (!data) {
|
||||||
};
|
var request = new XMLHttpRequest();
|
||||||
|
request.open('GET', '/dokku/assets/versions.json', true);
|
||||||
|
request.setRequestHeader("Cache-Control", "no-cache, no-store");
|
||||||
|
|
||||||
request.send();
|
request.onload = function() {
|
||||||
|
if (request.status >= 200 && request.status < 400) {
|
||||||
|
var data = JSON.parse(request.responseText);
|
||||||
|
// store for 1 day
|
||||||
|
ls2.save('max-versions', data, 86400);
|
||||||
|
processVersions(data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
request.onerror = function() {
|
||||||
|
// There was a connection error of some sort
|
||||||
|
};
|
||||||
|
|
||||||
|
request.send();
|
||||||
|
} else {
|
||||||
|
processVersions(data);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user