Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Disable cache of admin panels index.html

default discord avatar
chiefkoshilast year

Hey!



Is there any way I can disable the admin panel's index.html cache or add s-max-age=0? I use Koyeb for deployments and with each deployment I am faced with a white screen of death as its trying to load old hashes of the JS files. The index.html file seems to always be cached.



Solved it by hijacking res.end and res.write.



app.use("*", (req, res, next) => {
    if (req.path.includes("api")) return next();
    // Force no cache for admin
    // Hijack res.write
    const originalWrite = res.write;
    const originalEnd = res.end;
    const originalSend = res.send;
    //@ts-expect-error
    res.write = (...restArgs) => {
        if (
            !res.headersSent &&
            String(res.getHeader("Content-Type")).includes("text/html")
        ) {
            res.set(
                "Cache-Control",
                "s-maxage=0, max-age=0, must-revalidate, no-cache, no-store",
            );
        }
        originalWrite.apply(res, restArgs);
    };

    // Hijack res.end
    //@ts-expect-error
    res.end = (...restArgs) => {
        if (
            !res.headersSent &&
            String(res.getHeader("Content-Type")).includes("text/html")
        ) {
            res.set(
                "Cache-Control",
                "s-maxage=0, max-age=0, must-revalidate, no-cache, no-store",
            );
        }
        originalEnd.apply(res, restArgs);
    };

    // Hijack res.send
    //@ts-expect-error
    res.send = (...restArgs) => {
        if (
            !res.headersSent &&
            String(res.getHeader("Content-Type")).includes("text/html")
        ) {
            res.set(
                "Cache-Control",
                "s-maxage=0, max-age=0, must-revalidate, no-cache, no-store",
            );
        }
        originalSend.apply(res, restArgs);
    };

    next();
});
    Star on GitHub

    Star

    Chat on Discord

    Discord

    online

    Can't find what you're looking for?

    Get dedicated engineering support directly from the Payload team.