简体   繁体   English

注销后如何在不使用浏览器缓存的情况下从服务器重新加载角度应用程序

[英]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.

相关问题 如何在不重新加载的情况下将单个元素从浏览器发送到服务器 - how to send a single element from browser to server without reload 如何强制浏览器重新加载角度模板文件而不缓存它? - How to force a browser to reload angular template file and not cache it? 如何从服务器中使用新的js和html刷新Angular应用,但不重新加载浏览器窗口 - How to refresh an angular app with new js and html from the server, but without reloading the browser window 在angular2中注销后,如何通过浏览器后退按钮禁止用户访问上一页? - How to disable users from accessing previous page by browser back button after logout in angular2? 每当清除 angular 7 中的浏览器缓存时,如何强制浏览器注销用户? - How can i force browser to logout user whenever clearing the browser cache in angular 7? 注销后如何清除浏览器缓存(内存/磁盘缓存)? - How can I clear browser cache (memory / disk cache) after logout? 如何强制从浏览器缓存重新加载当前页面 - How to force reload of current page from browser cache 重新加载页面后,IE浏览器缓存未清除 - IE browser cache not clearing after reload the page Nativescript应用程序无需使用服务器即可从本地浏览器接收数据 - Nativescript app to receive data from local browser without using a server 重新加载或注销后如何保留复选框 state? - How to keep checkbox state after reload or logout?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM