浏览器重新启动时 HTML5 离线功能不起作用

发布于 2025-01-08 01:01:45 字数 1244 浏览 3 评论 0原文

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

有时它工作得很好,但在某些情况下它会表现得很奇怪。我试图找出原因以及如何解决它。

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

当出现问题时,

  • 浏览到我的页面 http://domain/App 注意: 我没有包含斜杠在 /App 之后,
  • 我被 sammy 重定向到 http://domain/App/#/
  • 一切都被缓存(包括图像)
  • 我离线了,我为此使用虚拟机,所以我拔掉虚拟网络适配器
  • 我关闭浏览器
  • 我重新打开浏览器并浏览到我的页面 http://domain/App/#/
  • 除了图像之外,内容正在显示
  • 如果在步骤 #1 中我浏览到 http://domain/App/ 包括斜杠。

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

    ??

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

    我的缓存清单看起来像这样,

    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
    

    I am using the offline HTML5 functionality to cache my web application.

    It works fine some of the time, but there are certain circumstances where it has weird behaviour. I am trying to figure out why, and how I can fix it.

    I am using Sammy, and I think that might be related.

    Here is when it goes wrong,

  • Browse to my page http://domain/App note: I haven't included a slash after the /App
  • I am then redirected to http://domain/App/#/ by sammy
  • Everything is cached (including images)
  • I go offline, I am using a virtual machine for this, so I unplug the virtual network adapter
  • I close the browser
  • I reopen the browser and browse to my page http://domain/App/#/
  • The content is showing except for the images
  • Everything works fine if in step #1 I browse to http://domain/App/ including the slash.

    There are some other weird states it gets into where the sammy routes are not called, so the page remains blank, but I haven't been able to reliably replicate that.

    ??

    UPDATE: The problem is that the above steps caused problems before. It is now working when I follow the above steps, so it is hard to say what is going on exactly. I am starting from a consistent state every time because I am starting from a snapshot in a VM.

    My cache manifest looks like this,

    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
    

    如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

    评论(1

    乖乖兔^ω^ 2025-01-15 01:01:45

    我也遇到了类似的问题。

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

    这是我用来测试这个的代码片段(尽管不是解决方案)

    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
                }
            }
        });
    

    I'm running into a similar issue as well.

    I think part of the problem is that jquery ajax is misinterpreting the response. I believe sammy is using the jquery to make the ajax calls, which is leading to the errors.

    Here's a code snippet i used to test for this (though not a solution)

    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
                }
            }
        });
    
    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文