【问题标题】:How to use Appcache with web frameworks?如何将 Appcache 与 Web 框架一起使用?
【发布时间】:2015-06-02 14:07:33
【问题描述】:

我有一个关于更改main page的问题,我使用Tornado,在Tornado中,每次到达服务器时都会生成一个特殊值,它是一个避免xsrf attack的令牌,但是当我使用.appcache 文件,问题是它缓存了所有内容!我只显示缓存static,如css, js, fonts,这是它包含的内容:

CACHE MANIFEST
# v = 2
/static/css/meteo.css
/static/css/semantic.min.css
/static/js/jquery-2.1.1.min.js
/static/css/main.css
/static/js/semantic.min.js
/static/js/geo.js
/static/js/meteo.js
/static/fonts/icons.woff2
/static/fonts/icons.woff
/static/fonts/WeatherIcons-Regular.woff
NETWORK:
/
FALLBACK:

它不起作用,/ 被缓存了!

那么如何使用新框架做到这一点,我们不在路由中创建html 文件,而是绑定到函数/类的uri

Here is a video I made about it

而且似乎master 总是被缓存:

更新:From this page,现在不行了!

但是,你说,我们为什么不缓存 HTML 文件,而是缓存所有其他文件。 好吧。 AppCache 有一个“主条目”的概念。主条目是一个 HTML 文件,它在指向清单文件的 html 元素中包含 manifest 属性(这是创建 HTML5 appcache BTW 的唯一方法)。任何此类 HTML 文件都会自动添加到缓存中。这在很多时候是有道理的,但并非总是如此。特别是,当 HTML 文档频繁更改时,我们不希望它被缓存(因为页面的陈旧版本很可能会像我们刚刚看到的那样提供给用户)。

有没有办法超越这个?嗯,AppCache 有一个想法 NETWORK 白名单,指示 appcache 始终使用 文件的在线版本。如果我们添加我们不想要的 HTML 文件怎么办 缓存到这个?对不起,没有骰子。主条目中的 HTML 文件保留 缓存,即使包含在 NETWORK 白名单中。明白了吗。 可怜的 AppCache 没有制定这些规则。他只是跟着他们 字面上地。他不是个混蛋,他是%^&*的痛苦者,总 “工作价值”。

【问题讨论】:

    标签: node.js html tornado html5-appcache offline-caching


    【解决方案1】:

    我得到了解决方案from here

    我创建了一个hack.html,其中包含:

    <!DOCTYPE HTML>
    <html>
    <head>
     <meta charset="utf-8">
     <title>Hack 4 Manifest</title>
    </head>
    
    <body>
      {% raw xsrf_form_html() %}
    </body>
    </html>
    

    然后

    在主页添加这个:

    <iframe style='display: none;' src='/hack'></iframe>
    

    然后在龙卷风中:

    (r"/hack", handlers.Hack),
    
    class Hack(MainHandler):
        @tornado.gen.coroutine
        def get(self):
            self.render("hack.html")
    

    然后我使用 javascript 调用:

    xsrf = $("iframe").contents().find("input").val()
    $("#laat").html('<input id="lat" type="hidden" name="lat"></input><input type="hidden" name="_xsrf" value='+xsrf+'><input id="lon" type="hidden" name="lon"></input><input class="ui fluid massive yellow button" value="Get forecast" type="submit"/>');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-26
      • 1970-01-01
      • 1970-01-01
      • 2010-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-08
      相关资源
      最近更新 更多