[英]AngularJS browser cache route pages disable
我有一个使用 AngularJS 和 Bootstrap 的网站。 问题在于客户端浏览器中的缓存。 我发布了一些东西......客户端从缓存中获取旧东西。 我正在使用 angular-ui-router-0.3.1 进行路由。
我在$stateProvider
使用cache: false
但什么都没有。
这是我用来路由 HTML 页面的索引:
<!DOCTYPE html>
<html lang="en" ng-app="mainApp">
<head>
<meta http-equiv="expires" content="0">
<meta http-equiv="cache-control" content="no-cache, must-revalidate, post-check=0, pre-check=0">
<meta http-equiv="pragma" content="no-cache">
...
</head>
<body>
<div ui-view></div>
</body>
</html>
和 app.js:
var app = angular.module('mainApp', ['ui.router','angularUtils.directives.dirPagination']);
app.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('index', {
cache: false,
url: '/',
templateUrl: 'pages/main.html'
})
.state('presentation', {
cache: false,
url: '/presentation',
templateUrl: 'pages/presentation.html'
})
.state('about', {
cache: false,
url: '/about',
templateUrl: 'pages/about.html'
})
...
$urlRouterProvider.otherwise('/');
});
例如,最大的问题是,当我更新演示文稿页面时,客户端没有得到更新。
即使它存储在缓存中,我应该怎么做才能强制加载路由页面??? 或者怎么告诉客户端浏览器,不缓存路由页面??
第 1 步:在您的配置中创建一个变量以用作查询字符串,例如:
var version = 1.01;
然后像这样更改所有templateUrl
:
templateUrl: 'pages/main.html?v=' + version
每次将新版本推送到生产时,请更新version
变量。 这应该会强制浏览器重新加载模板,因为它无法知道新的查询字符串代表什么。
第 2 步:如果您还想强制重新加载主页,以下是满足所有浏览器的最低要求:
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.