Atitit.h5 web webview性能提升解决方案-----fileStrore缓存离线存储+http方案

1. 业务场景 android+webview h5 css背景图性能提升1

2. 根据标准,到目前为止,H5 一共有6种缓存机制,有些是之前已有,有些是 H5 才新加入的。1

2.1. 各种方案的比较,如下图2

3. Attilax的解决之道 file 缓存+http3

3.1. 图片的下载3

3.2. Jsbridge 4android5

3.3. http协议6

4. 参考8

1. 业务场景 android+webview h5 css背景图性能提升

图片的缓存大概儿需要500m的规模..

2. 根据标准,到目前为止,H5 一共有6种缓存机制,有些是之前已有,有些是 H5 才新加入的。

1.

浏览器缓存机制

2.

3.

Dom Storgage(Web Storage)存储机制

4.

5.

Web SQL Database 存储机制

6.

7.

Application Cache(AppCache)机制

8.

9.

Indexed Database (IndexedDB)

10.

11.

File System API

12.

2.1. 各种方案的比较,如下图

作者::  ★(attilax)>>>   绰号:老哇的爪子 ( 全名::Attilax Akbar Al Rapanui 阿提拉克斯 阿克巴 阿尔 拉帕努伊 ) 汉字名:艾龙,  EMAIL:1466519819@qq.com

转载请注明来源: http://www.cnblogs.com/attilax/

3. Attilax的解决之道 file 缓存+http

按照以上的方式都不适合...最好的还是file api缓存..file api android 默认不支持...使用jsbridge解决..

显示图片,直接使用文件路径,不能显示,,使用file://协议也不能..使用datauri,三,android上慢的要命,业马是base64 encode decode闪的..

子好使用http协议了..走ok兰...

3.1. 图片的下载

package com.attilax.img;

public class imgx4android {

public String save2localHighPerf(String urlx, String localpath,

String urlHostPart) {

String imageFileNoPath = PathUtil4android.getPathNohostNoApproot(

urlx, urlHostPart);

String sdRoot = new PathUtil4android().getInnerSDCardPath(); // /storage/sdcard

localpath = localpath.replace("$sd$", sdRoot);

//

localpath = localpath + "/" + imageFileNoPath;

// saveBitmap(imageFilePath,localpath);

File f = new File(localpath);

if (f.exists()) {

// f.delete();

return localpath;

}else

{

PathUtil4android.createAllPath(localpath);

}

try {

urlx = UrlX.encodeURI(urlx);

URL url = new URL(urlx);

HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setConnectTimeout(7000);

conn.setRequestMethod("GET");

int responseCode = conn.getResponseCode();

if (responseCode != 200)

throw new RuntimeException(

"cant get img from getBitmapFromUrl:" + urlx

+ "   responseCode:" + responseCode);

// if (responseCode == 200) {

InputStream inputStream = conn.getInputStream();

// Bitmap bitmap = BitmapFactory.decodeStream(inputStream);

StreamUtil strx = new StreamUtil();

FileOutputStream out = new FileOutputStream(localpath);

strx.convertStream(inputStream, out);

strx.flushNclose(out);

return localpath;

// }

catch (Exception e) {

ExUtil.throwEx(e);

}

return localpath;

}

3.2. Jsbridge 4android

@JavascriptInterface

public    String invoke4(  String method,String p2,String p3,String p4)

{

List<String> li=new ArrayList();

li.add(p2);li.add(p3);li.add(p4);

Object[] oa=li.toArray();

return invoke(method,oa);

}

// sdk17�汾���ϼ���ע�� solu click btn ma fein ..

@JavascriptInterface

public    String invoke(  String method,   Object... p1) {

String classname = refx.getClassName(method);

String meth_name = refx.getMethodName(method);

Object o;

boolean flag = true;

String trace = "$def e";

try {

o = ConstructorUtils.invokeConstructor(Class.forName(classname),

null);

catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

// throw new RuntimeException(e);

flag = false;

trace = ExUtil.getTrace(e);

return trace;

}

if (flag) {

try {

return (StringMethodUtils.invokeMethod(o, meth_name, p1);

catch (Exception e) {

Throwable e2=e;

if( e instanceof InvocationTargetException)

{

// TODO Auto-generated catch block

e2=e.getCause();

// throw new RuntimeException(e);

}

e2.printStackTrace();

trace = ExUtil.getTrace(e2);

return trace;

}

}

// Handler handler = new Handler();

// // Callable<V>

// handler.post(new Runnale(){

//

// public void run(){

//

// // 更新UI界面元素代码

//

// }

//

// });

// handler.

return trace;

}

3.3. http协议

public class AtiHttpServer {

public static void main(String[] args) {

HTTPServer srv=new HTTPServer();

srv.open("127.0.0.1", 7788);

srv.addRequestListener(new HTTPRequestListenerImp());

System.out.println("---http start");

srv.start();

System.out.println("---http finish over");

}

public class HTTPRequestListenerImp   implements org.cybergarage.http.HTTPRequestListener

{

private void httpRequestRecieveX(HTTPRequest httpReq) {

String f=httpReq.getParameterValue("file");

String filePaths = httpReq.getParameterValue("file");

try

{

File file = new File(filePaths);

// ��ȡ�ļ��Ĵ�С

long contentLen = file.length();

// ��ȡ�ļ�����

String contentType = FileUtil.getFileType(filePaths);

// ��ȡ���ļ���

InputStream contentIn =new   FileInputStream(file);

if (contentLen <= 0 || contentType.length() <= 0

|| contentIn == null)

{

httpReq.returnBadRequest();

return;

}

HTTPResponse httpRes = new HTTPResponse();

httpRes.setContentType(contentType);

httpRes.setStatusCode(HTTPStatus.OK);

httpRes.setContentLength(contentLen);

httpRes.setContentInputStream(contentIn);

httpReq.post(httpRes);

contentIn.close();

}

catch (MalformedURLException e)

{

httpReq.returnBadRequest();

return;

}

catch (SmbException e)

{

httpReq.returnBadRequest();

return;

}

catch (IOException e)

{

httpReq.returnBadRequest();

return;

}

}

4. 参考

H5 缓存机制浅析 移动端 Web 加载性能优化 - OPEN 开发经验库.html

Atitit.h5 web webview性能提升解决方案-----fileStrore缓存离线存储+http方案的更多相关文章

  1. Atitit 开发进度 开发效率提升解决方案

    Atitit 开发进度  开发效率提升解决方案 1.1. 使用4gl语言 dsl语言尽可能 1 1.2. Ssd+高屏幕显示器,提升硬件 1 1.3. 汉字命名规范,可以大力提升可读性与效率 1 1. ...

  2. VNF网络性能提升解决方案及实践

    VNF网络性能提升解决方案及实践 2016年7月 作者:    王智民 贡献者:     创建时间:    2016-7-20 稳定程度:    初稿 修改历史 版本 日期 修订人 说明 1.0 20 ...

  3. Web 应用性能提升 10 倍的 10 个建议

    转载自http://blog.jobbole.com/94962/ 提升 Web 应用的性能变得越来越重要.线上经济活动的份额持续增长,当前发达世界中 5 % 的经济发生在互联网上(查看下面资源的统计 ...

  4. Web 应用性能提升的 10 个建议

    建议一.利用反向代理服务器加速和保护应用 如果 Web 应用运行在一台独立的电脑上,性能问题的解决方案是显而易见的:换一台更快的电脑,里面加上更多的处理器.内存.快速磁盘阵列等等.然后在这台新电脑上运 ...

  5. Web开发须知的浏览器内幕 缓存与存储篇(2)

    本文禁止转载,由UC浏览器内部出品. 3. HTTP Cache 综述 HTTP Cache是完全按照IETF规范实现的,最新的RFC规范地址是 https://tools.ietf.org/html ...

  6. Web开发须知的浏览器内幕 缓存与存储篇(1)

    本文禁止转载,由UC浏览器内部出品. 0.前言 大纲 浏览器缓存和存储相关的功能分为四类: 加载流程 Memory Cache Application Cache(简称AppCache) HTTP C ...

  7. 【web Api性能提升技巧】(2)从DataReader手工创建Json字符串

    这个思路是从 一篇文章,关于<提升web api的性能>上看到的.自己实践了一番,写下步骤. 传统的DataReader是遵循这样的一个步骤: While(reader.Read()) { ...

  8. Hibernate4教程六:性能提升和二级缓存

    抓取策略(fetching strategy)是指:当应用程序需要在(Hibernate实体对象图的)关联关系间进行导航的时候,Hibernate如何获取关联对象的策略.抓取策略可以在O/R映射的元数 ...

  9. web前端效率提升之禁用缓存-遁地龙卷风

    1.使用场景 我用的是Chrome,Ctrl+F5并不是在任何时候都能清楚缓存,这样很影响效率,下面的方式可以在开发者工具打开的使用禁止浏览器缓存任何资源, 还是出现不及时更新的情况,就要考虑服务器是 ...

随机推荐

  1. 论MORMOT序列的JSON格式

    论MORMOT序列的JSON格式 JSON 数据使用 UTF-8 编码 BLOB 字段值会用 Base64编码 JSON数据是一个对象数组: [ {"col1":val11,&qu ...

  2. Google Breakpad 完全解析(二) —— Windows前台实现篇

    原创文章,转载请标明出处:Soul Apogee (http://bigasp.com),谢谢. 好,看完了如何使用breakpad,我们现在看看breakpad在Windows下到底是如何实现的呢? ...

  3. [Linux Memory] 用/proc/stat计算cpu的占用率

    转载自:http://blog.csdn.net/pppjob/article/details/4060336 在Linux下,CPU利用率分为用户态,系统态和空闲态,分别表示CPU处于用户态执行的时 ...

  4. sql 改动表以及表字段

    用SQL语句加入删除改动字段 1.添加字段      alter table docdsp    add dspcode char(200)      alter table tbl add meet ...

  5. 查看SQLServer的QUOTED_IDENTIFIER等配置

    DBCC USEROPTIONS SELECT SESSIONPROPERTY('QUOTED_IDENTIFIER') quotedidentifier SELECT SESSIONPROPERTY ...

  6. iOS:quartz2D绘图(画一些简单的图形,如直线、三角形、圆、矩形、文字等)

    前一篇几乎已经详细介绍了Quartz2D的所有知识,这一篇以及后面就不废话了,主要是用具体的实例来演示绘图效果. 这里我们先来绘制一些简单的图形(如直线.三角形.圆.矩形.文字.图像),它有两种方式可 ...

  7. (C语言版)链表(四)——实现双向循环链表创建、插入、删除、释放内存等简单操作

    双向循环链表是基于双向链表的基础上实现的,和双向链表的操作差不多,唯一的区别就是它是个循环的链表,通过每个节点的两个指针把它们扣在一起组成一个环状.所以呢,每个节点都有前驱节点和后继节点(包括头节点和 ...

  8. linux grep的选项

    grep  -i          关闭大写和小写敏感性 grep      -v    打印全部不包括. . 的行(屏蔽某些条目) grep     -l     打印包括模式的文件名称 grep  ...

  9. 安装64位office时提示已安装32位的office

    运行 regedit,进入到HKEY_CLASSES_ROOT\Installer\Products下,删除0000510开头的项,没有00005我把00002....的删了也可以

  10. Junit核心——测试集(TestSuite)

    关于测试集,实质就是包含若干个测试类的集合,通过一个具体的实例,让我们来了解一下Junit的测试集 package org.yezi.junit; public class Calcaute { pu ...