The invention relates to a web page loading optimization strategy under iOS, which comprises the following steps: the user opens the cache loading function, the user tries to open the web page, generates the hash value of the corresponding URL of the web page, and uses the hash value as the keyword to obtain it by the cache. If it can be successfully obtained, the current time is obtained with the hash value as the keyword. Get the cache time from the cache, if the difference between the cache time and the current time does not exceed the expiration time, then get the cache path from the cache with the hash value as the key, if the cache path exists, get the cache file, if the cache file exists, then use the cache to load the web page. When the above judgment is not satisfied, a normal network request is initiated. The invention uses a buffer to store the data obtained by network requests, associates these data with the URL, no longer initiates network requests when the same URL is repeatedly accessed within a certain period of time, but obtains the data from the buffer according to the strategy, which is fast and efficient, reduces the occupation of network bandwidth and saves system resources. Avoid the Catton situation caused by network problems.
【技术实现步骤摘要】
一种iOS下web页面加载优化策略
本专利技术涉及页面加载
,具体说是一种iOS下web页面加载优化策略。
技术介绍
在iOS系统中,加载网页、文件、html常用UIWebView控件(可以简单理解为一个在iOS端显示网页的一个控件),UIWebView控件是用来加载加载网页数据的一个框。UIWebView可以用来加载pdf、word、doc等等文件。在UIWebView控件加载网页、文件、html等时,通常首先要有一个资源的地址即URL用于定位资源,然后把URL告诉给服务器,请求从该URL获取数据,这一请求将发给服务器。UIWebView继承于UIView,因此,其初始化方法和一般的view一样,通过alloc和init进行初始化,其加载数据的方式有三种:第一种:-(void)loadRequest:(NSURLRequest*)request;这是加载网页最常用的一种方式,通过一个网页URL来进行加载,这个URL可以是远程的也可以是本地的。第二种:-(void)loadHTMLString:(NSString*)stringbaseURL:(NSURL*)baseURL;这个方法需要将httml文件读取为字符串,其中baseURL是我们自己设置的一个路径,用于寻找html文件中引用的图片等素材。第三种:-(void)loadData:(NSData*)dataMIMEType:(NSString*)MIMETypetextEncodingName:(NSString*)textEncodingNamebaseURL:(NSURL*)baseURL ...
【技术保护点】
1.一种iOS下web页面加载优化策略,其特征在于,包括如下步骤:用户开启缓存加载功能,用户尝试打开web页面,将web页面对应的url生成hash值,以hash值为关键字去缓存器获取,如果不能成功获取,则发起正常网络请求,如果能成功获取,则获取当前时间,以hash值为关键字,从缓存器中获取缓存时间,如果缓存时间和当前时间的差值,超过失效时限,则发起正常网络请求,如果缓存时间和当前时间的差值,未超过失效时限,则以hash值为关键字,从缓存器中获取缓存路径,如果缓存路径不存在,则发起正常网络请求,如果缓存路径存在,则获取缓存文件,如果缓存文件不存在,则发起正常网络请求,如果缓存文件存在,则使用缓存加载web页面。
【技术特征摘要】
1.一种iOS下web页面加载优化策略,其特征在于,包括如下步骤:用户开启缓存加载功能,用户尝试打开web页面,将web页面对应的url生成hash值,以hash值为关键字去缓存器获取,如果不能成功获取,则发起正常网络请求,如果能成功获取,则获取当前时间,以hash值为关键字,从缓存器中获取缓存时间,如果缓存时间和当前时间的差值,超过失效时限,则发起正常网络请求,如果缓存时间和当前时间的差值,未超过失效时限,则以hash值为关键字,从缓存器中获取缓存路径,如果缓存路径不存在,则发起正常网络请求,如果缓存路径存在,则获取缓存文件,如果缓存文件不存在,则发起正常网络请求...
【专利技术属性】
技术研发人员:邱扬,
申请(专利权)人:北京酷我科技有限公司,
类型:发明
国别省市:北京,11
还没有人留言评论。发表了对其他浏览者有用的留言会获得科技券。