【问题标题】:AngularJS "caching" on slow internet connection :(AngularJS在慢速互联网连接上“缓存” :(
【发布时间】:2015-02-27 02:10:02
【问题描述】:

我有一个简单的 angularjs 应用程序,例如:

module = angular.module 'testFooBarModule', ['ngResource']

module.factory 'FooBar', ($resource)->
    $resource 'foobar/target', {},
        load:
            method: 'GET'
            cache: false # no effect
            headers: 
                'Cache-Control': 'no-cache' # no effect

module.controller 'FooBarCtrl', ($scope, FooBar)->
    FooBar.load (result)->
        console.log result

使用家庭 wlan 或移动 hspa 等高速互联网,一切正常。请求已触发,服务器给了我一个独特的响应。 但是对于像 edge 或 gprs 这样的 2G 互联网,服务器不会收到任何请求,而 angularjs 应用程序总是给我相同的结果。不会发生错误。 “no-cache”标头也被发送。

我不知道出了什么问题。谁能帮帮我?

对不起我的英语:D

最好的问候。

【问题讨论】:

  • 到目前为止,我已经看到其他人通过在 GET 请求中添加动态参数(例如时间戳)来模拟新请求来解决这个问题。在这种情况下还没有看到使用无缓存。
  • 你也可以使用角度承诺来缓存数据。

标签: angularjs caching web-applications coffeescript


【解决方案1】:

这可能不是角度问题。我的猜测是互联网提供商正在为安全带宽做一些神奇的 http 代理,或者您的底层操作系统正试图为您缓存它。

一些选项:

  • 使用 HTTPS 应该可以防止提供者中间人的行为,而且对于移动应用来说无论如何都是个好主意!
  • 使用像时间戳这样笨拙的动态参数
  • 使用 POST 或 PUT 作为动词
  • 在服务器响应中添加“Cache-Control: no-cache”标头,我认为这是最干净的解决方案

【讨论】:

    猜你喜欢
    • 2017-07-13
    • 1970-01-01
    • 1970-01-01
    • 2011-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多