【问题标题】:HTML5 Offline Functionality Doesn't Work When Browser Restarted重新启动浏览器时 HTML5 脱机功能不起作用
【发布时间】:2012-02-22 02:15:31
【问题描述】:

我正在使用离线 HTML5 功能来缓存我的 Web 应用程序。

它在某些时候可以正常工作,但在某些情况下它会出现奇怪的行为。我正在尝试找出原因,以及如何解决它。

我正在使用 Sammy,我认为这可能是相关的。

这是出错的时候,

  • 浏览到我的页面http://domain/App 注意:我没有在 /App 之后添加斜杠
  • 然后我被 sammy 重定向到 http://domain/App/#/
  • 所有内容都被缓存(包括图像)
  • 我下线了,我用的是虚拟机,所以拔掉了虚拟网卡
  • 我关闭浏览器
  • 我重新打开浏览器并浏览到我的页面http://domain/App/#/
  • 除了图片以外的内容都在显示
  • 如果在第 1 步中我浏览到 http://domain/App/(包括斜杠),一切正常。

    它会进入一些其他奇怪的状态,即未调用 sammy 路由,因此页面保持空白,但我无法可靠地复制它。

    ??

    更新:问题是上述步骤之前引起了问题。当我按照上述步骤操作时,它现在正在工作,所以很难说到底发生了什么。我每次都是从一致的状态开始,因为我是从 VM 中的快照开始的。

    我的缓存清单如下所示,

    CACHE MANIFEST
    
    javascripts/jquery-1.4.2.js
    javascripts/sammy/sammy.js
    javascripts/json_store.js
    javascripts/sammy/plugins/sammy.template.js
    
    stylesheets/jsonstore.css
    
    templates/item.template
    templates/item_detail.template
    
    images/1Large.jpg
    images/1Small.jpg
    
    images/2Large.jpg
    images/2Small.jpg
    
    images/3Large.jpg
    images/3Small.jpg
    
    images/4Large.jpg
    images/4Small.jpg
    
    index.html
    

    【问题讨论】:

      标签: html offline offline-caching sammy.js


      【解决方案1】:

      我也遇到了类似的问题。

      我认为部分问题是 jquery ajax 误解了响应。我相信 sammy 正在使用 jquery 进行 ajax 调用,这会导致错误。

      这是我用来测试的代码 sn-p(虽然不是解决方案)

      this.get('#/', function (context) {
      
          var uri = 'index.html';
      
          //  what i'm trying to call
          context.partial(uri, {});// fails on some browsers after initial caching
      
          //  show's that jquery's ajax is misinterpreting
          //  the response
          $.ajax({
              url:uri,
              success: function(data, textStatus, jqXHR){
                  alert('success')
                  alert(data);
              },
              error: function(jqXHR, textStatus, errorThrown){
                  alert('error')
                  if(jqXHR.status == 0){  //  this is actually a success
                      alert(jqXHR.responseText);
                  }else{
                      alert('error code: ' + jqXHR.status)    // probably a real error
                  }
              }
          });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-02-22
        • 1970-01-01
        • 2019-06-05
        • 1970-01-01
        • 1970-01-01
        • 2017-11-11
        • 1970-01-01
        相关资源
        最近更新 更多