使用单页面应用程序进行缓存

时间:2015-09-09 08:40:52

标签: single-page-application browser-cache sapui5 cache-manifest manifest.cache

我有一个OpenUI5应用程序;我的应用程序只有一个htlm页面(index.html),一些js文件(用于逻辑控制器)和一些xml文件(用于视图)。

该应用是一个单页应用程序;这是我的index.html首页:

<!DOCTYPE html>
<html manifest="app.appcache">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta charset="UTF-8">
    <!--<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
    <meta http-equiv="cache-control" content="max-age=0" />
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="expires" content="0" />
    <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
    <meta http-equiv="pragma" content="no-cache" />-->

    <title>My App</title>

    <!-- UI5 Bootstrap with OpenUI5 -->
    <script id="sap-ui-bootstrap"

            type="text/javascript"
            src="resources/openui/sap-ui-core.js"
            data-sap-ui-theme="sap_bluecrystal"
            data-sap-ui-xx-bindingSyntax="complex"
            data-sap-ui-libs="sap.m"
            data-sap-ui-resourceroots='{
            "ui5bp": "./",
            "model": "./model"
             }'
        >
    </script>



    <!-- Custom Styles -->
    <link rel="stylesheet" type="text/css" href="css/style.css" />

   <script>

        new sap.m.Shell("Shell", {
            showLogout : false,
            app : new sap.ui.core.ComponentContainer({
                name : 'ui5bp'
            }),
            homeIcon : {
                'phone' : "img/57_ogo.jpg",
                'phone@2' : "img/114_logo.jpg",
                'tablet' : "img/72__logo.jpg",
                'tablet@2' : "img/144_logo.jpg",
                'precomposed': false,
                'favicon' : "img/favicon.ico"
            }
        }).placeAt('root');
   </script>
</head>

<body class="sapUiBody" id="root">
</body>

</html>

这是我的清单文件app.appcache(我在每个新版本都进行了更改)

CACHE MANIFEST
#APP VERSION 1.0.4-rc4

#insert here files to cache

#insert here files to NOT cache
NETWORK:
*

OK!但现在我在我的服务器和BOOM上复制了应用程序!某些页面被重新加载但其他页面没有...(例如我有一个登录XML视图,其中我显示了更新的发行版本以及未更新的设置对话框的XML) 为什么我有这种行为?我希望浏览器在每次重新加载时重新加载每个文件

P.S。 如果我通过F5重新加载应用程序,问题仍然存在。 如果我在index.html文件中添加这些元标记,问题仍然存在

    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
    <meta http-equiv="cache-control" content="max-age=0" />
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="expires" content="0" />
    <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
    <meta http-equiv="pragma" content="no-cache" />

强制浏览器重新加载整个应用程序的唯一方法是手动取消缓存:

enter image description here

1 个答案:

答案 0 :(得分:0)

如果您可以在SPA中包含Java Servlet Filter,这是一个可行的解决方案:CorrectBrowserCacheHandlerFilter.java

基本上,当您的浏览器请求静态文件时,服务器会将每个请求重定向到同一个请求,但使用哈希查询参数(例如?v=azErT),这取决于目标静态文件的内容。 / p>

这样做,浏览器永远不会缓存在index.html中声明的静态文件(因为它总是会收到302 Moved Temporarily),但只会缓存带有哈希版本的服务器(服务器)将为他们回答200。因此,浏览器缓存将有效地用于具有哈希版本的静态文件。

免责声明:我是CorrectBrowserCacheHandlerFilter.java的作者。

相关问题