美文网首页
使用vue ios bfcache失效

使用vue ios bfcache失效

作者: 小银 | 来源:发表于2019-05-07 16:17 被阅读0次

ios框架wkwebview
H5使用vue作为框架
现象:
一个聊天框,跳其他页面后再反回去内容被刷了
尝试打印pageshow-》e.persisted显示false。说明bfcahe失效

在看问题之前先了解下MessageChannel

参考1
参考2

然后看下webkit相关源码
首先是PageCache文件描述了页面缓存相关的信息

static bool canCacheFrame(Frame& frame, DiagnosticLoggingClient& diagnosticLoggingClient, unsigned indentLevel)
{
.....
 Vector<ActiveDOMObject*> unsuspendableObjects;
    if (frame.document() && !frame.document()->canSuspendActiveDOMObjectsForDocumentSuspension(&unsuspendableObjects)) {
        PCLOG("   -The document cannot suspend its active DOM Objects");
        for (auto* activeDOMObject : unsuspendableObjects) {
            PCLOG("    - Unsuspendable: ", activeDOMObject->activeDOMObjectName());
            diagnosticLoggingClient.logDiagnosticMessage(DiagnosticLoggingKeys::unsuspendableDOMObjectKey(), activeDOMObject->activeDOMObjectName(), ShouldSample::Yes);
            UNUSED_PARAM(activeDOMObject);
        }
        logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::cannotSuspendActiveDOMObjectsKey());
        isCacheable = false;
    }
.......
}
//canSuspendActiveDOMObjectsForDocumentSuspension()主要处理是否可缓存信息

然后看下对应ScriptExecutionContext文件

有个canSuspendForDocumentSuspension方法

bool ScriptExecutionContext::canSuspendActiveDOMObjectsForDocumentSuspension(Vector<ActiveDOMObject*>* unsuspendableObjects)
{
    checkConsistency();

    bool canSuspend = true;

    forEachActiveDOMObject([&](auto& activeDOMObject) {
        if (!activeDOMObject.canSuspendForDocumentSuspension()) {
            canSuspend = false;
            if (unsuspendableObjects)
                unsuspendableObjects->append(&activeDOMObject);
            else
                return ShouldContinue::No;
        }
        return ShouldContinue::Yes;
    });

    if (unsuspendableObjects) {
        // Remove activeDOMObjects that have been destroyed while we were iterating above.
        unsuspendableObjects->removeAllMatching([&](auto* activeDOMObject) {
            return !m_activeDOMObjects.contains(activeDOMObject);
        });
    }

    return canSuspend;
}

那有哪些activeDOMObject对象呢,在webcore下搜了下 53个
可以看下worker

bool Worker::canSuspendForDocumentSuspension() const
{
    // FIXME: It is not currently possible to suspend a worker, so pages with workers can not go into page cache.
    return false;
}
//canSuspendForDocumentSuspension 直接返回false 用了 new Worker也不会生效了
//
//idb操作的
bool IDBObjectStore::canSuspendForDocumentSuspension() const
{
    return false;
}
//indexedDB.open('test')
//eventsource操作的
bool EventSource::canSuspendForDocumentSuspension() const
{
    // FIXME: We should return true here when we can because this object is not actually currently active.
    return false;
}
//new EventSource

再看(MessagePort文件)[https://github.com/WebKit/webkit/blob/master/Source/WebCore/dom/MessagePort.cpp]

bool MessagePort::canSuspendForDocumentSuspension() const
{
    return !hasPendingActivity() || (!m_started || m_closed);
}
//canSuspendForDocumentSuspension拿到false(由于条件限制无法开调试看具体原因)

实际现象是使用

var nmc=    new MessageChannel();
//必须有下面这句
nmc.port1.onmessage =function(){}
//vue2.6之前版本用了MessageChannel  
//解决办法
//1. MessageChannel=null
//2.ios多开webview

相关文章

  • 使用vue ios bfcache失效

    ios框架wkwebviewH5使用vue作为框架现象:一个聊天框,跳其他页面后再反回去内容被刷了尝试打印page...

  • iOS SDK 系统 Bug 汇总及解决方案

    iOS 10.3 使用NSStrikethroughStyleAttributeName添加删除线失效 添加删除线...

  • 小程序的iOS和Android兼容问题

    篇一: 1.margin在IOS中失效 在页面中元素使用margin值,在某些IOS设备下会出现失效的情况,而安卓...

  • vue ios 表单失效

    问题描述:暂时只发现ios会出现以上问题,在我的项目里有一个表单元素绝对定位,不知道怎么就影响了其他表单元素的显示...

  • vue热替换失效根本原因

    新手刚开始使用vue时,常会遇见一个坑,那就是热替换失效。 什么?你跟我说使用官方的vue-cli去构建,我就是使...

  • Vue材料清单

    Vue问题整理 @mouseover 第三方组件例如el-button中使用类似api失效,此时需要使用@mous...

  • Vue中使用setTimeout,this 失效

    在做Vue项目时使用setTimeout,在里面调用this.add()方法,报错this.add 不是一个函数 ...

  • vue-各种兼容问题

    使用vue框架在ios里面返回白屏问题记录

  • iOS 自带 删除线 iOS 10.3失效

    当使用 iOS自带富文本 实现中划线的时候 在iOS10.3上划线失效 原因是因为Label 上的文字只要包含...

  • vue @click点击事件失效

    在使用vue的UI组件iView.design时,点击搜索按钮click事件失效。 以上代码中click事件无效,...

网友评论

      本文标题:使用vue ios bfcache失效

      本文链接:https://www.haomeiwen.com/subject/fnwroqtx.html