android下对webview的优化
访问量: 3401
refer to:
https://www.b4x.com/android/forum/threads/webview-slow-but-web-browser-fast.51800/
空间载入慢的网页的终极解决办法 http://www.cnblogs.com/xinye/p/3144139.html
largetHeap
<Application> 标签中,增加: largeHeap属性, = true.
HardwareAccelerator
AndroidManufest.xml 中, 增加: 相关的配置项. 如下 .
<application
android:name=".MainApplication"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@drawable/android_template"
android:label="@string/app_name"
android:largeHeap="true"
webview 使用jquery 的话,进行优化:
http://stackoverflow.com/questions/5780353/jquery-mobile-loaded-into-an-android-webview
Android的 Webview是把所有的html都渲染了之后,才会展现的.
所以,我们要根据这个进行优化.
1. 让页面今早整个出来
2. 图片的话,该延迟加载就延迟加载.
3. 一些 jQuery(document.ready(){ }) 的方法, 不要使用jQuery.ready , 而是使用 setTimeout(function(){}, 10) 这样的方法. 页面就不会认为你的函数应该在加载前执行了.
使用LazyLoad来下载,执行js:
https://github.com/rgrove/lazyload/<script src="/css/j/lazyload-min.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
loadComplete(){
//instead of document.read()
}
function loadscript()
{
LazyLoad.loadOnce([
'/css/j/jquery-1.6.2.min.js',
'/css/j/flow/jquery.flow.1.1.min.js',
'/css/j/min.js?v=2011100852'
], loadComplete);
}
setTimeout(loadscript,10);
</script>
目前的症状: 渲染地址的页面太慢了.
我的 -> 我的地址. 2 秒.
肉眼观察: 第一次不用考虑. 第二次第三次 , 连js 都不请求. 客户端只请求一个 后台interface. 可以说 链接减少到了极致.
为什么还慢呢? 似乎问题出在 打开window ( activity, fragment ) 速度太慢?
思路: 加上 时间戳, 看看 加载的速度如何.