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:[email protected]

转载请注明来源: 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

时间: 2024-08-07 00:01:25

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

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

转载自http://blog.jobbole.com/94962/ 提升 Web 应用的性能变得越来越重要.线上经济活动的份额持续增长,当前发达世界中 5 % 的经济发生在互联网上(查看下面资源的统计信息). 我们现在所处的时代要求一直在线和互联互通,这意味着用户对性能有更高的期望.如果网站响应不及时,或者应用有明显的延迟,用户很快就会跑到竞争者那边去. 例如,Amazon 十年前做的一项研究表明,网页加载时间减少 100 毫秒,收入就会增加  1%.最近另一项研究凸显了一个事实,就是有一半以上

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

本文禁止转载,由UC浏览器内部出品. 3. HTTP Cache 综述 HTTP Cache是完全按照IETF规范实现的,最新的RFC规范地址是 https://tools.ietf.org/html/rfc7234.它的作用就是保存可缓存的响应以备重新使用,在下次请求时可减少响应时间和网络带宽.只有GET和HEAD method会缓存. 浏览器的优化 浏览器是过滤了部分没有意义进行缓存的响应头才保存到磁盘,例如Connection(keep-alive).www-authenticate等.这

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

本文禁止转载,由UC浏览器内部出品. 0.前言 大纲 浏览器缓存和存储相关的功能分为四类: 加载流程 Memory Cache Application Cache(简称AppCache) HTTP Cache Cookie Storage Javascript API Web Storage Indexed Database File API Cache Storage(Service Worker的核心功能) Filesystem API Quota Management API 前进后退 P

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

这个思路是从 一篇文章,关于<提升web api的性能>上看到的.自己实践了一番,写下步骤. 传统的DataReader是遵循这样的一个步骤: While(reader.Read()) { //创建对象,赋值,添加到集合 } //返回Json.序列化(集合) 现在我们采用的是手工拼接Json字符串:通过解析DataReader的数据格式.内容,采用StringBuilder.Append这种方式进行手工拼接. 避免了每次初始化对象.序列化集合所带来的内存.时间上的消耗.在查询数据量很大集合时,

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

1.使用场景 我用的是Chrome,Ctrl+F5并不是在任何时候都能清楚缓存,这样很影响效率,下面的方式可以在开发者工具打开的使用禁止浏览器缓存任何资源, 还是出现不及时更新的情况,就要考虑服务器是否完成部署了,额,这种情况你可能再用Eclipse之流开发. 2.方式方法 Chrome49设置方式如下: a.F12打开开发者工具 b c 58版本的Network上 QQ:1947147481  一起进步吧! 赞赏

SQL Server 2014里的性能提升

在这篇文章里我想小结下SQL Server 2014引入各种惊艳性能提升!! 缓存池扩展(Buffer Pool Extensions) 缓存池扩展的想法非常简单:把页文件存储在非常快的存储上,例如SSD硬盘,用来扩展缓存池.缓存池扩展来得非常方便,如果你不能给你的数据库服务器物理上增加更多的内存,可以考虑使用缓存池扩展. 资源调控器(Resource Governor) 资源调控器首次是在SQL Server 2008里引入的,但那个时候还不是个成熟的技术,因为你不能在存储级别调控I/O操作,

YbSoftwareFactory 代码生成插件【二十一】:Web Api及MVC性能提升的几个小技巧

最近在进行 YbSoftwareFactory 的流程功能升级,目前已经基本完成,现将用到的一些关于 Web Api 及 MVC 性能提升的一些小技巧进行了总结,这些技巧在使用.配置上也相当的简单,但通常都能大大提高应用程序的性能,希望对大家有用. 一.缓存 为了避免每次请求都去访问后台的资源,我们一般会考虑将一些更新不是很频繁的,可以重用的数据,通过一定的方式临时地保存起来,后续的请求根据情况可以直接访问这些保存起来的数据,这种机制就是所谓的缓存机制.缓存分为页面输出缓存,内存数据缓存和缓存依

如何从请求、传输、渲染3个方面提升Web前端性能

什么是WEB前端呢?就是用户电脑的浏览器所做的一切事情.我们来看看用户访问网站,浏览器都做了哪些事情: 输入网址 –> 解析域名 -> 请求页面 -> 解析页面并发送页面中的资源请求 -> 渲染资源 -> 输出页面 -> 监听用户操作 -> 重新渲染. 通过上面的路径可以看出浏览器分为请求.传输.渲染三部分来实现用户的访问,本文就从这三个部分来浅析如何提升WEB前端性能. 请求浏览器为了减少请求传输,实现了自己的缓存机制.浏览器缓存就是把一个已经请求过的Web资源

8 种提升 ASP.NET Web API 性能的方法

ASP.NET Web API 是非常棒的技术.编写 Web API 十分容易,以致于很多开发者没有在应用程序结构设计上花时间来获得很好的执行性能. 在本文中,我将介绍8项提高 ASP.NET Web API 性能的技术. 1) 使用最快的 JSON 序列化工具 JSON 的序列化对整个 ASP.NET Web API 的性能有着关键性的影响. 在我的一个项目里,我从 JSON.NET 序列化工具转到了 ServiceStack.Text 有一年半了. 我测量过,Web API 的性能提升了20