Disable Cache on Self-Hosted Builds?

Hello, we frequently update our self-hosted app, and advising users to clear cache and cookies after each update seems impractical. Is there a simple fix to disable all caching? Adding ?v=somenumber to files doesn’t seem to resolve the issue.

Try setting the related response headers on your server, e.g.:

Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate
Expires: 0
Surrogate-Control: no-store

Okay, I’ve also added this at the top of start.js file

pc.Asset.prototype.getFileUrl = function () {
    var file = this.file;

    if (! file || ! file.url)
        return null;

    var url = file.url;

    if (this.registry && this.registry.prefix && ! ABSOLUTE_URL.test(url))
        url = this.registry.prefix + url;

    return url;
};

Cache is definitely busted on desktops, but it doesn’t solve the issue on Android Chrome unfortunately :face_with_raised_eyebrow:

Okay I’ve finally managed to get it updating on Mobile Android Chrome

  1. < > .htaccess
<IfModule mod_headers.c>
    Header set Cache-Control "no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires 0
</IfModule>
  1. < > start.js
	pc.Asset.prototype.getFileUrl = function () {
        const file = this.file;

        if (!file || !file.url)
            return null;

        let url = file.url;

        if (this.registry && this.registry.prefix && !pc.ABSOLUTE_URL.test(url))
            url = this.registry.prefix + url;

        // add file hash to avoid hard-caching problems
        if (file.hash) {
            const separator = url.indexOf('?') !== -1 ? '&' : '?';
            url += separator + 't=' + file.hash;
        }

        return url;
    };
  1. < > index.html (query at the end of each file) Example:
<body>
    <script src="__modules__.js?v=0.2"></script>
    <script src="__start__.js?v=0.2"></script>
    <script src="__loading__.js?v=0.2"></script>
</body>
2 Likes