当前位置:网站首页>An in-depth understanding of the implementation principle of Hybrid
An in-depth understanding of the implementation principle of Hybrid
2022-08-09 19:44:00 【Ink fragrance ^_^】
file and schema protocol
webview
hybrid technology: how to use file, schema protocol and webview control to achieve?
Origins of hybrid technology
How is hybrid technology implemented?
Summary
Reference link
Before introducing JSBridge, let's briefly introduce hybrid.
In front-end mobile development, there are three main types:
Native APP development (led by Android and iOS);
HTML5 web app development;
Mixed development of native APP and HTML5, that is, hybrid technology;
Origin of hybrid technology
First, let's compare the web app and the native app:
image.png
Combining the advantages and disadvantages of the two, the Hybrid application was born.Simply put, a hybrid application is a web application that wraps a native application's shell.Hybrid Technology:
Compatible with multiple platforms, you can call the functions provided by the mobile phone system, and you can download it in the app store;
Its performance and user experience are not as good as native apps but higher than web apps;
It's online time depends on whether the function is implemented by web or native;
Hybrid technology needs to understand native APP development, front-end development, and back-end development to complete, so the development cost is high and the maintenance cost is also high.
How is hybrid technology implemented?
The realization of hybrid technology depends on the following two points:
file and schema protocols;
webview; each is described below.
file and schema protocol
These three protocols are often used in apps:
file protocol: used to open local files, the advantage is fast;
https protocol: http and ssl/tls protocol, this protocol needs to send network requests, which is naturally much slower than the file protocol;
schema protocol: the protocol used for client and front-end communication;
Some schema protocols of WeChat are listed as follows:
weixin://dl/scan Scan
weixin://dl/moments Moments
webview
webview is a browser control based on the webkit kernel in the mobile phone system, with a rendering engine and a JS engine, used to display html pages.It is the same principle as the browser to display the page, you can think of it as a castrated version of the browser.Simply put, it is a container for displaying pages, for example:
image.png
The red box part is the webview control/container that displays the page, and outside the red box are other controls and components controlled by native (native app).
hybrid technology: how to use file, schema protocol and webview control to achieve?
There are 2 ways for webview to load the page:
To load a web page, just pass in the http URL;
Load local pages, here are two subdivisions:
Load the html page under the assets directory: In this way, you can access local offline files without making network requests, which can reduce the user's data traffic;
Load cached to the local page: mainly used for offline cache of the page, such as storing the html file cache in the local file directory.For details, see the two ways WebView loads pages - web pages and local pages: https://www.cnblogs.com/zxxiaoxia/p/6831085.html
If the webview loads a local page, it is generally called through the file protocol, as follows:
webView.loadUrl("file:///android_asset/staticHtml.html");
Then calling and rendering the front-end page directly through the file protocol in the webview container is definitely faster than sending an https request in html5 and then rendering it, because we mentioned earlier that the file protocol is faster than https to obtain resources.
The webview container obtains the front-end page resources through the file protocol call as shown below:
image.png
If the page resources loaded in the webview are frequently iterated, how can the user be updated synchronously?
At this point, we can use the native app's api to send network requests to obtain server-side page resources. What are the advantages or differences compared to html5 to send requests to obtain resources?This is the case, through the native app, we can request all the pages of the server while opening the app. When we want to display the page, the page resources are already in the local area. After getting it, we can directly render and execute js, which is fast.A lot, that is, the processing of preloading page resources.This is not to go to the server to request resources every time the app is opened, but to request resources only when the server resources are updated, which can reduce the time for resource loading.
Implementation idea: Only when the user version number and the server version number are inconsistent, the resource request is made, as shown below:
image.png
In the client (ie app), how to interact with the front-end page is to use the schema protocol mentioned above, which is simply to intercept the url with the schema format we agreed to do some processing.Details will be discussed later.
Summary
Simply put, hybrid technology realizes page loading, rendering, display, and communication with native and server through webview and file and schema protocols.Hybrid is not perfect, whether to use it depends on your actual application scenarios and needs.
Reference link:
hybrid technology https://blog.csdn.net/yexudengzhidao/article/details/82811185
There are two ways for WebView to load pages - web pages and local pages: https://www.cnblogs.com/zxxiaoxia/p/6831085.html
What is the relationship between webview and mobile browser?https://www.zhihu.com/question/40871670
边栏推荐
- MySQL索引的B+树到底有多高?
- About the common Hook encapsulation of DOM (2)
- International Soil Modeling Consortium-ISMC
- 【代码审计】——PHP项目类RCE及文件包含下载删除
- 偷偷盘点一下各大互联网公司的实习薪资
- 试试使用 Vitest 进行组件测试,确实很香。
- Logic unauthorized and horizontal and vertical unauthorized payment tampering, verification code bypass, interface
- Prometheus full installation
- 郭炜(郭大侠):九个关于开源的 Yes or No
- 本机号码一键登录原理
猜你喜欢
随机推荐
逻辑越权和水平垂直越权支付篡改,验证码绕过,接口
kubernetes之helm简介、安装、配置
快捷键修改typora字体----自制脚本
【燃】是时候展现真正的实力了!一文看懂2022华为开发者大赛技术亮点
WinForm(四)一种实现登录的方式
如何通过 open-local 玩转容器本地存储? | 龙蜥技术
冷冻电镜聚类中心(2D Class)粒子图像的解析
嵌入式软件开发的特点和流程
智能工具管理系统
approach和method的区别
原油等特殊期货开户要求和豁免
小家电控制板开发——未来小家电行业的发展方向
偷偷盘点一下各大互联网公司的实习薪资
《ABP Framework 极速开发》 - 教程首发
Apache Doris 社区 PMC 杨政国:开源项目如何在自身和社区的需求中取得平衡?
Account opening requirements and exemptions for special futures such as crude oil
《.NET物联网从零开始》系列
微服务:事务管理
太细了!阿里大佬耗时39天整理出一份Redis进阶笔记,满满的干货
openEuler 熊伟:如何看待开源社区中的 SIG 组织模式?