image

------------------ ???????? ------------------
??????: "????"<284437...@qq.com>;
????????: 2019??1??22??(??????) ????8:28
??????: "dev"<dev@weex.incubator.apache.org>;

????: ?????? prerender discuss



 
 
### ??????
 


 
#### ????????
 


 
1. ??????????????????????????????:
 
> WXPrerenderManager.getInstance().preRenderByXXX()
 


 
??????
 
> *  
> ????????????????WXSDKIntance.renderByUrl()????renderByTemplete()????????????????????????????????????????????
 
> *  
> ????????????????????????????????????????????????????view??renderContainer????????????????????????????????????????????????????????????????????????????????????????????
 
> *  
> ????????????templete??????????????????url??????????????????????url????????????????????????????????url????key????????????instance????????????templete????????????url??
 
> *  ??????????????application context????
 


 
2. ??????????????????????????????????WXSDKInstance:
 
> WXPrerenderManager.getInstance().fetchPreload(String url)
 


 
??????
 
> * ??????instance????????????????????????????????????WXSDKInstance
 


 
3. 
????????????instance??realRender()????????activity??context??????????component??View??
 


 
??????
 
> * ????????????false????????????????????????????????????render??????
 


 
??????????
 


 
```java
 
    // ????????????????????
 


 
    // ??????????????????????????????????????????????????????????
 
    int realWidth = 
(int)DeviceInfoUtil.getWidth(BaseApplication.getApplicationContext());
 
    int realHeight = (int) 
(DeviceInfoUtil.getHeight(BaseApplication.getApplicationContext()) - 
TitleBar.getStatusBarHeight() - TitleBar.getTitleBarHeight());
 


 
    // ????????????????????????????
 
    HashMap<String, Object> loadExturas = new HashMap<>();
 
    loadExturas.put(WXSDKInstance.BUNDLE_URL, url);
 
    loadExturas.put("userAgent", userAgent);
 
    loadExturas.put("cookie", cookie);
 
    loadExturas.put("viewSize", String.format("{\"width\":%d,\"height\":%d}", 
realWidth, realHeight));
 
    WXPrerenderManager.getInstance().preRenderByUrl(
 
            BaseApplication.getApplicationContext(),
 
            "Weex_Preload",
 
            url,
 
            loadExturas,
 
            null,
 
            realWidth,
 
            realHeight,
 
            WXRenderStrategy.APPEND_ONCE);
 


 


 
    // ??????????????instance
 
    bool hasPrerenderPage = false;
 
    if (!TextUtils.isEmpty(webUrl)) {
 
        mWXSDKInstance = WXPrerenderManager.getInstance().fetchPreload(webUrl);
 
        if (mWXSDKInstance != null) {
 
            mHasPrerenderPage = true;
 
        }
 
    }
 
    if (!hasPrerenderPage) {
 
        mWXSDKInstance = new WXSDKInstance(context);
 
    }
 


 
    if (hasPrerenderPage) {
 
        boolean result = mWXSDKInstance.realRender(context);
 
        // ??????????????????????????????????????
 
        if (!result) {
 
            mWXSDKInstance = new WXSDKInstance(context);
 
            // ??????????????????
 
            renderWithOutPreload(url);
 
        }
 
    } else {
 
        renderWithOutPreload(url);
 
    }
 
```
 


 
#### ??????????
 
??????????????????????weex????render????????????????????????WXSDKInstance??render??????????onRenderSuccess????????????????????????????
 


 
??????????????????????weex??????render????:
 
> render -> http????JsBundle -> weexcore createInstance -> jsCore????jsBundle 
> -> ????????dom action -> weex frameWork????dom action -> 
> ????component??view??????layout?? -> android????????view
 


 
????trace????????????????????weex????????????????????????????2????????
 


 
1. jsCore????jsBundle??????
 
2. ????????dom action????????dom action??????
 


 
????2??????????????weex????????????????????????????????????????????????????????????
 
1. ??????
 
2. ????????
 


 
????????????????????????????????????????????????????????????????
 


 
????????????????????????
 
> ???? view -> ????????
 


 
??????????weex render????view????????????????????real 
render??????????????????????????????????????????????
 


 
??????????????????????????
 


 
????????prerender??????
 
> prerender -> http????JsBundle -> weexcore createInstance -> 
> jsCore????jsBundle -> ????????dom action -> weex frameWork????dom action -> 
> ??????????componentNode
 


 
realRender??????
 
> realrender -> ????componentNode????component??view -> ????????
 


 
#### ??????????
 


 
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
 


 
??????????????????????????????????????render->rendersuccess??????????1.2s(????????????jsBundle??????????????????????????80ms)????????????????????????????????160-180ms??
 


 
????????????????????realRender????????????????componnetNode????component??view??????????????????????????????????view????????
 


 
??????????????node??????????????????message??????view 
anr??????????????????component??node??????????post????weex render 
thread??????action??????????????????????????????????????????????????????????????????????????100ms????????
 


 
#### ????????????????
 


 
1. ??????recyclerList????????UpdateComponentDataAction??????????
 
2. ??????????????InvokeMethod??InvokeMethodAction????????
 
3. ??????????????????????????????????
 
4. ????????????????????????????????????????????module????????????????????????
 


 


 


 





------------------ ???????? ------------------
??????: "????"<shenyua...@gmail.com>; 
????????: 2019??1??22??(??????) ????5:31
??????: "dev"<dev@weex.incubator.apache.org>; 
????: Re: prerender discuss



If this is about feature/issue discussion, rename the mail title to [DISCUSS] 
XXXX next time.
Describe the design or theory of pre-rendering as there are lots of code change 
without a document.

Thanks



> ?? 2019??1??22????17:05?????? <284437...@qq.com> ??????
> 
>  solve the problem that the weex page is slow to open, we implemented the 
> pre-rendering scheme. In many scenarios, we think that modifying the action 
> in Java is the least modified solution. You are welcome to give suggestions 
> for the prerender implementation.PR:
> https://github.com/apache/incubator-weex/pull/1978 
> <https://github.com/apache/incubator-weex/pull/1978>;

Reply via email to