zoukankan      html  css  js  c++  java
  • 关于HMLT5离线缓存的痛,痛经有多痛就有多痛(hybrid应用加载)

    一、先看下脑图

    二、前面一篇文章简单的说了下manifest文件的缓存。

      前面的文章能解决问题,但是带来了更多的致命问题,最后想到这个办法。

      也碰到了一些关于HTML加载执行的问题,主要是页面和JS执行的顺序问题。

      关于源码暂时还没整理出来~~有需要了解的可以找我交流~~~

    (function(window, undefined) {
    				//资源请求
    				function loadResource(resources, callback) {
    					if (Object.prototype.toString.call(resources) !== "[object Array]"){return;}
    					var index = 0,cacheStr='',errorCache=false;
    					(function _load(ary) {
    						var opt = ary.shift();
    						if (!opt) {
    							localStorage.cacheStrJs=cacheStr;
    							if(!errorCache){
    								localStorage.versioning=versioning;
    								"function" == typeof callback && callback();
    							}else{
    								//资源文件请求异常进行二次请求,直到全部缓存资源成功才结束
    								loadResource([
    									{path: 'css/index.css',sName: 'index'},
    									{path: 'js/utils.js',sName: 'utils'},
    									{path: 'js/keycode.js',sName: 'keycode'},
    									{path: 'js/videoplay.js',sName: 'videoplay'},
    									{path: 'js/initial.js',sName: 'initial'},
    									{path: 'js/keyevent.js',sName: 'keyevent'},
    									{path: 'js/uianimate.js',sName: 'uianimate'}, 
    									{path: 'js/videoapp.js',sName: 'videoapp'}
    								], function () {
    					        		cache();
    					        		console.log("二次加载完成完成完成!");
    								});
    							}
    	                    }
    						try {
    							var url;
    							if(index<8){
    				            	url=opt.path+'?v='+versioning;
    							}else{
    								url=opt.path;
    							}
    							$.ajax({
    								url : url,
    								type : "GET",
    								dataType:'text',
    								success : function (data) {
    									if(index<8){
    					            		if(index==0){
    					            			localStorage[opt.sName]=data;
    					            		}else{
    							            	cacheStr+=data;
    					            		}
    									}
    					            	index++;
    									_load(ary);
    								},
    								error : function() {
    									index++;
    									if(index<8){
    										errorCache=true;
    										_load(ary);
    									}
    								}
    							});
    	                      }catch (e){
    	                      }
    					})(resources);
           		};
     			loadResource([
    				{path: 'css/index.css',sName: 'index'},
    				{path: 'js/utils.js',sName: 'utils'},
    				{path: 'js/keycode.js',sName: 'keycode'},
    				{path: 'js/videoplay.js',sName: 'videoplay'},
    				{path: 'js/initial.js',sName: 'initial'},
    				{path: 'js/keyevent.js',sName: 'keyevent'},
    				{path: 'js/uianimate.js',sName: 'uianimate'}, 
    				{path: 'js/videoapp.js',sName: 'videoapp'},
    				{path: 'images/iocl.png'},
    				{path: 'images/ico.png'},
    				{path: 'images/other.png'},
    				{path: 'images/ylowbg.png'},
    				{path: 'images/tvb.png'},
    				{path: 'images/zyi.png'},
    				{path: 'images/comic.png'},
    				{path: 'images/child.png'},
    				{path: 'images/movie.png'},
    				{path: 'images/serch.png'},
    				{path: 'images/moive.png'},
    				{path: 'images/history.png'},
    				{path: 'images/tv.png'},
    				{path: 'images/zy.png'},
    				{path: 'images/video.png'},
    				{path: 'images/indxbg.jpg'},
    				{path: 'images/movdet.jpg'},
    				{path: 'images/tvdet.jpg'},
    				{path: 'images/zydet.jpg'},
    				{path: 'images/hotdef.png'},
    				{path: 'images/kidsdet.jpg'},
    				{path: 'images/comicdet.jpg'},
    				{path: 'images/fao.jpg'},
    				{path: 'images/his.jpg'},
    				{path: 'images/favdet.jpg'},
    				{path: 'images/hisdet.jpg'},
    			], function () {
            		cache();
            		console.log("加载完成完成完成!");
    			});
           		})(window);
    

      

  • 相关阅读:
    07微博绑定用户接口(我们的约定还算数嘛。)
    08vue 微博回调空页面(最终还是没能留住你。)
    06vue微博回调空页面 (你还会来嘛)
    05微博回调接口 (念念不忘,必有回响吗。)
    04vue获取微博授权url(再也得不到你了。)
    03生成微博授权的url接口(再也没有你了)
    02微博开放平台使用方法 (在哪也不会再遇见你了。)
    01微博三方登录原理讲解(再多三方登录,也看不到你的信息。)
    Django-celery异步短信验证码(0)
    Django之重写用户表注册接口(redis缓存)
  • 原文地址:https://www.cnblogs.com/AnthonyLee/p/3134720.html
Copyright © 2011-2022 走看看