当前位置:网站首页>android html5页面加载缓存优化
android html5页面加载缓存优化
2022-06-12 02:02:00 【五个木】
程序猿日常
苦逼的程序员对自己好点!
LZCache使用
https://github.com/wugemu/WebTest
Application中初始化 代码如下:
//初始化
List<String> cacheList=new ArrayList<String>();//缓存的资源
cacheList.add(".js");
cacheList.add(".css");
cacheList.add(".ico");
cacheList.add(".png");//图片
cacheList.add(".jpg");
cacheList.add(".gif");
cacheList.add(".action?");//页面请求
CacheUtil.initOnlyCache(512 * 1024 * 1024, cacheList);//最大缓存512MB
注:讨论 哪些数据进行缓存
initOnlyCache(long cacheMax,List<String> cacheList)
cacheMax最大缓存容量,只对cacheList中的文件进行缓存(字符串包含)
initAllCache(long cacheMax,List<String> noCacheList)
cacheMax最大缓存容量,只对noCacheList中的文件不进行缓存(字符串包含)
1首次加载优化
CacheUtil.loadUrl(WebView webview, Content content, String url, Map<String ,String> headpara);
该方法实现webview加载与 html内容请求异步,html内容获取后会立即展示,无需等待资源加载完成,并缓存到本地可同步更新,使用此方法可以实现离线模式(缓存文件完全)。
注: html5中有请求时,需要实现跨域设置;
2缓存机制优化
webView.setWebViewClien(new WebViewClientCache());
示例代码如下:
webView.setWebViewClient(new WebViewClientCache(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
});
边栏推荐
- Redis startup and shutdown commands
- MySQL table common operation mind map
- Software engineering course: Chapter 2 software problem definition and feasibility analysis after class exercises
- websocket 切后台10秒后 关闭掉了
- 阿里云oss文件上传系统
- Linux (centos7) installer mysql - 5.7
- 为什么我们要使用谷歌搜索广告?
- 广泛匹配修饰符符号已经被弃用,请勿使用
- 2022 blind box applet app has become a new drainage outlet for enterprises
- How to buy children's serious illness insurance, what to pay attention to and how to choose products
猜你喜欢

Why do we use Google search ads?

Tiobe - programming language ranking in June 2022

The resignation of the chief oracle engineer was furious: MySQL is a terrible database, so it is recommended to consider PostgreSQL!

Three main factors determining advertising quality

Fatal error in launcher: unable to create process using

Ce soir - là, j'ai battu mon collègue...

决定广告质量的三个主要因素

为什么我们要使用谷歌搜索广告?

西南林业大学“西林链”通过工信部电子标准院功能测试 | FISCO BCOS案例

Annotate your own point cloud dataset with labelcloud open source tool as a tutorial of Kitti annotation format (support PCD and bin point clouds)
随机推荐
Modification of system module information of PHP security development 12 blog system
Redis實現消息隊列的4種方案
PyGame alien invasion
Linux(CentOS7)安裝MySQL-5.7版本
2022 blind box applet app has become a new drainage outlet for enterprises
What are the preparations for setting up Google search advertising series?
Educational knowledge and ability test questions of primary and secondary school educational endowment examination in the second half of 2019 (middle school) - subjective questions
Software engineering course: Chapter 2 software problem definition and feasibility analysis after class exercises
Redis cluster + sentinel mode + replicas
"Xilin chain" of Southwest Forestry University passed the functional test of Electronic Standards Institute of the Ministry of industry and information technology | FISCO bcos case
如何最大化的利用各种匹配方式? ——Google SEM
What are the advantages of adaptive search advertising?
Redis startup and shutdown commands
阿里云oss文件上传系统
Installing MySQL version 5.5 database for Linux (centos6)
Design principle [Demeter's Law]
Database
Implementation scheme of iteration and combination pattern for general tree structure
How much coverage is appropriate for children's serious illness insurance? Which product is the best?
[untitled]