[英]How to reload angular app from server, without using browser cache, after logout
I am working on an Angular app. 我正在开发Angular应用。 On logout we delete some cookies, and then we want to reload the page, including all the JS scripts, from the server (not from the browser cache). 注销时,我们删除一些cookie,然后要从服务器(而不是从浏览器缓存)重新加载页面,包括所有JS脚本。
The server has some auth in place that will redirect to a login form if there are no cookies. 服务器上有一些身份验证,如果没有cookie,它将重定向到登录表单。
Following MDN docs, to reload the page without using the cache, I used window.location.reload(forceReload);
在MDN文档之后,为了不使用缓存就重新加载页面,我使用了window.location.reload(forceReload);
with forceReload=true
. 使用forceReload=true
。 But it's not working. 但这不起作用。 The page is reloaded but from the cache not from the server. 页面被重新加载,但是从缓存而不是从服务器加载。
$http({
method: 'GET',
url: api.baseUrl + '/logout',
}).then(function() {
// Should reload the current page, without using the cache
window.location.reload(true);
return;
});
EDIT 编辑
The above code is correct, it does reload the page without using the cache. 上面的代码是正确的,它确实在不使用缓存的情况下重新加载了页面。
The problem was with auth on our server side. 问题出在我们服务器端的auth。 I would delete this question, but Stack Overflow is discouraging to delete questions with answers. 我将删除此问题,但是不鼓励使用Stack Overflow删除带有答案的问题。
You can remove the http requests cache with 您可以使用以下方法删除http请求缓存
$cacheFactory.get('$http').removeAll();
also for each request, you can specify if you want to cache the response or not : 同样对于每个请求,您都可以指定是否要缓存响应:
factory('User', function($resource) {
return $resource(yourapi + 'route', {}, {
get: {
cache: false, // you can disable cache for login for example !
method: 'GET'
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.