Ruby on rails 清单中未定义的HTML5缓存清单缓存请求

Ruby on rails 清单中未定义的HTML5缓存清单缓存请求,ruby-on-rails,html,local-storage,html5-appcache,Ruby On Rails,Html,Local Storage,Html5 Appcache,我正在开发一个应用程序,在这个应用程序中,我需要缓存特定的请求 所以我一直在努力使用HTML5缓存 这是我的清单文件 CACHE MANIFEST # 2d25a26de3a1148a2fa5e534325f84cca2184090174c6ba451451c54f71f52d6 assets/application.js assets/application.css assets/glyphicons/png/glyphicons_064_lightbulb.png assets/jquery

我正在开发一个应用程序,在这个应用程序中,我需要缓存特定的请求

所以我一直在努力使用HTML5缓存

这是我的清单文件

CACHE MANIFEST
# 2d25a26de3a1148a2fa5e534325f84cca2184090174c6ba451451c54f71f52d6
assets/application.js
assets/application.css
assets/glyphicons/png/glyphicons_064_lightbulb.png
assets/jquery-mobile/ajax-loader.gif
assets/jquery-mobile/icons-18-white.png
application.manifest

NETWORK:
/project_show
/application.manifest 
现在我在
/projects\u show
页面中看到了如下内容

<div data-role="header" class="header">
</div>

<div data-role="content" class="content">
</div>  

<div data-role="footer" class="footer" style="text-align:center">   
</div>  

<script type="text/javascript">
    <%= store_key %>
</script>

<script id="header" type="text/template">
    <h1>Listing of {{ carName   }}</h1>
</script>

<script id="content" type="text/template">
    <span>{{ pageName }}</span>
</script>

<script id="footer" type="text/template">
    <span> CopyRight &copy; {{ user }} </span> 
</script>


<script type="text/javascript">

    $(document).ready(function() {
        if (window.navigator.onLine) {
                $.getJSON('/project/2.json',function(data) {

                   localStorage.setItem("acura",JSON.stringify(data));

                        var carTemplate = $('#header').html();
                        var pageTemplate = $('#content').html();
                        var footerTemplate = $("#footer").html();
                        $('div.header').html(Mustache.to_html(carTemplate, data));
                    $('div.content').html(Mustache.to_html(pageTemplate, data));
                $('div.footer').html(Mustache.to_html(footerTemplate,data));

                    })

      else {
            var data = JSON.parse(localStorage.getItem("acura"))
            var carTemplate = $('#header').html();
                var pageTemplate = $('#content').html();
                var footerTemplate = $("#footer").html();
            $('div.header').html(Mustache.to_html(carTemplate, data));
                $('div.content').html(Mustache.to_html(pageTemplate, data));
                $('div.footer').html(Mustache.to_html(footerTemplate,data));
      }             
    })
</script>

{{carName}}清单
{{pageName}}
版权及副本;{{user}}
$(文档).ready(函数(){
if(window.navigator.onLine){
$.getJSON('/project/2.json',函数(数据){
setItem(“acura”,JSON.stringify(data));
var carTemplate=$('#header').html();
var pageTemplate=$('#content').html();
var footerTemplate=$(“#footer”).html();
$('div.header').html(Mustache.to_html(carTemplate,data));
$('div.content').html(Mustache.to_html(页面模板,数据));
$('div.footer').html(Mustache.to_html(footerTemplate,data));
})
否则{
var data=JSON.parse(localStorage.getItem(“acura”))
var carTemplate=$('#header').html();
var pageTemplate=$('#content').html();
var footerTemplate=$(“#footer”).html();
$('div.header').html(Mustache.to_html(carTemplate,data));
$('div.content').html(Mustache.to_html(页面模板,数据));
$('div.footer').html(Mustache.to_html(footerTemplate,data));
}             
})
您可以看到这里的想法是,如果用户在线从服务器获取
json
响应,如果没有,则从
localStorage

不幸的是,由于这个原因,上面的代码不起作用

a) 缓存清单文件也在缓存
ajax
请求

现在可以看到我没有要求HTML缓存清单来缓存
json
请求

i、 e
/projects/2.json

谁能告诉我为什么会这样

如果将
GET
请求修改为
POST
请求,即
/projects/2.json的POST请求,而不是GET

但这不是我想要的任何建议


仅供参考,清单确实正确地遵循了清单文件,因为我还注意到我的
/projects
正在获取缓存,即使没有在
清单中定义

尝试将
/project/2.json
添加到清单的
网络
部分。然后,对该URL的请求应始终从服务器而不是从appcache


关于缓存的
/projects
页面:是否将该页面绑定到此appcache(通过在页面的
元素中具有
manifest=“…”
属性)?如果将页面绑定到appcache,页面本身始终隐式地是appcache的一部分(作为所谓的“主条目”).

这也让我发疯。我发现有效的方法是将“index.html”内容添加到清单的网络部分。按照您的工作方式,我认为您还需要添加“index.html”页眉和“index.html”页脚


我认为现在正在发生的是index.html被缓存。“内容”“页眉”和“页脚”是其中的一部分。因此,调用加载这些部分(在我的例子中是页面)由于index.html被缓存,ajax调用无法运行。通过向网络部分添加index.html内容,它会强制调用。

我也面临着这个问题,不知道这是否可以通过
post
Thanks解决。这可能是一个选项,但我相信从长远来看它不会起作用,因为问题也必须标记在rails
/projects/2中的
ruby-on-rails
。json
2可以被任何数字替换,如
/projects/999.json
/projects/1111.json
尝试为每个项目设置一个条目将很难也不可能实现
网络
部分中的条目使用前缀匹配,因此如果添加
/projects//code>您将匹配所有这些json URL。