Docly Developers
DocsUpdated 18 Oct 2026

Auto reload page if cached and outdated

Reload a cached page automatically when it has been updated on the server. The page carries the version it was rendered with; a small API function returns the current version, and the browser reloads when they differ.

API function - Mod.js

#/API/Mod.js

export default () => {
    // Returns only the version of the file - never its content.
    let fi = query.file ? docly.getFile(String(query.file)) : null;
    if (!fi) return {};

    return {
        Guid: fi.Guid,
        Timestamp: fi.LastModified.Ticks.toString()
    };
}

Javascript

Place this script in the page. It uses fetch, so it needs no jQuery. The values written into the script are the version the page was rendered with - that is the part that goes stale in the cache.

#let fi = docly.getFile(request.filepath)#
#if (fi) {#
<script>
    (function () {
        var renderedGuid = #JSON.stringify(fi.Guid)#;
        var renderedTimestamp = #JSON.stringify(fi.LastModified.Ticks.toString())#;
        var file = #JSON.stringify(request.filepath)#;

        fetch("~/API/Mod?file=" + encodeURIComponent(file), { cache: "no-store" })
            .then(function (r) { return r.ok ? r.json() : null; })
            .then(function (res) {
                if (!res || !res.Timestamp) {
                    console.warn("File version check failed.");
                    return;
                }
                if (res.Guid != renderedGuid || res.Timestamp != renderedTimestamp) {
                    console.log("Page is outdated. Reloading.");
                    location.reload();
                }
            });
    })();
</script>
#}#