簡體   English   中英

SPA Angular index.html未更新緩存(我使用緩存胸圍)

[英]SPA Angular index.html not updated cache (i use cache bust)

我在應用程序SPA中使用類似於此的簡單結構: http ://mcalthrop.github.io/angular-spa-demo/#/resources(tks示例mcalthrop)

在index.html(標頭)中有緩存(無效)的資產(js,css)的初始加載,此后,僅加載了模板和json(正文)AngularJS。

問題在於,它們是僅在用戶使用Ctrl + R(硬重載)或注銷時才加載隨安裝更新的功能。 我們的客戶可以花幾天的時間打開頁面。

報告了類似的問題: 刷新緩存的Angular SPA

我使用grails,角度為1.6,主動清除緩存。

找到“廣告素材”替代方案:

說明:在SPA資產文件上加載唯一的生命周期應用程序。 但是,就我而言,用戶登錄了很長時間才想要新版本的資產,而沒有新的登錄名。 因此,當出現新的js / css緩存失效時,我該怎么做,我刷新了頁面。 如果沒有,請繼續。

function urlAssetOk(url) {
        var http = new XMLHttpRequest();
        var urlWithoutCache = url + "?t=" + (new Date()).getTime();
        http.open('HEAD', urlWithoutCache, false);
        http.send();
        return http.status == 200;
    }

    function updatedCache() {
        var jsApplicationAsset = document.querySelectorAll('[class="application-asset"][src*=application-]')[0];
        var cssApplicationAsset = document.querySelectorAll('[class="application-asset"][href*=application-]')[0];
        var jsObsolete = jsApplicationAsset && !urlAssetOk(jsApplicationAsset.src) ? true : false;
        var cssObsolete = cssApplicationAsset && !urlAssetOk(jsApplicationAsset.src) ? true : false;

        if (jsObsolete || cssObsolete) {
            window.location.reload(true);
        }
    }

    window.onhashchange = function() {
        updatedCache();
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM