Auto reload page if cached and outdated Last updated: 14. Aug 2023
By the use this API-function and javascript you can automatically hard reload a page if it has been updated on server.
API function - Mod.js
#/API/Mod.js
var fi = docly.getFile(query.file);
var result = {
"Guid" : fi.Guid,
"Timestamp" : fi.LastModified.Ticks.toString()
};
return result;
Javascript
Place this script in your page. (requires jQuery)
<script>
$.get("~/API/Mod?file=#request.filepath#", function(res) {
if (!res.Timestamp) {
console.warn("File version check failed!");
return;
}
#let fi = docly.getFile(request.filepath)#
if (res.Guid != "#fi.Guid#") {
console.warn("File version check failed, mismatch. Reloading!", res.Guid, "/#request.Guid#");
location.reload(true);
}
else if (res.Timestamp && res.Timestamp != "#fi.LastModified.Ticks#") {
console.log("File check completed, file is outdated. Reloading!");
location.reload(true);
} else {
console.log("File check completed, already updated.", res.Timestamp, "#fi.LastModified.Ticks#");
}
});
</script>