是否可以缓存加载在iPhone UIWebView中的资源? [英] Is it possible to cache resources loaded in an iPhone UIWebView?

查看:137
本文介绍了是否可以缓存加载在iPhone UIWebView中的资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的应用程序加载一个网站优化的iPhone在 UIWebView

I have a simple app loading a site optimized for the iPhone in a UIWebView.

缓存似乎不起作用:

[webView loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString: url]
                                       cachePolicy: NSURLRequestUseProtocolCachePolicy
                                   timeoutInterval: 60.0]];

此远程页面中引用的任何内容(css,images,external javascript files)永远不会被缓存请求从不发送If-Modified-Since头或任何其他缓存控制方式。)

Any things referenced in this remote page (css, images, external javascript files) never get cached (the requests never send a If-Modified-Since header or anything else in the way of cache control.)

是否可能?似乎有一个常规的Cocoa WebView有一个委托方法被调用为每个资源请求和后加载( -didFinishLoadingFromDataSource:),你可以用来滚动自己的缓存..但这在这里似乎不适用。

Is it possible? It seems with a regular Cocoa WebView there a delegate methods that get called for each resource request and post load (-didFinishLoadingFromDataSource:) which you could use to roll your own caching.. but that does not seem applicable here.

我的整个页面(页面及其引用的资源)大约89K压缩..这在3G有些地方慢,甚至更糟糕超过EDGE。传入的请求至少表示它接受压缩( accept-encoding = gzip,deflate ),所以这是很好的。

My entire page (page and its referenced resources) is around 89K compressed.. which is slow over 3G in some spots and even worse over EDGE. Incoming requests are at least indicating that it accepts compression (accept-encoding=gzip, deflate), so that's good I suppose.

我读了这个yui研究,这似乎表示iPhone将每项缓存25k。唯一引用的是超过25k未压缩的是jquery(压缩但未压缩 - 它是30k)。一切都应该是可缓存的。在抓取的页面中没有任何引用的请求会触发服务器端的304.

I read this yui study, which seems to indicate that the iPhone will cache 25k per item. The only thing referenced that is over 25k uncompressed is jquery (packed but uncompressed - it is 30k). Everything else should be cacheable. No request for anything referenced in the page fetched is triggering a 304 on the server side.

那个yui研究是从一年前开始,我猜想用移动safari只要。

That yui study was from almost a year ago, and I am guessing with mobile safari only.

这是在原生iPhone应用程式中使用 UIWebView

This is using a UIWebView in a native iPhone app.

推荐答案

我看到的这个问题的一个解决方法是

One workaround of this problem as I see is to

1)下载HTML代码

1) download HTML code

2)将其存储在字符串

2) store it in the string

3)在其中查找所有外部链接

3) find all external links in it like

<img src="img.gif" width="..." height="..." />

4)下载所有

5 )替换为嵌入的Base64编码版本

5) replace them with embedded Base64-encoded version

<img src="data:image/gif;base64,R0lGODlhUAAPA...JADs= " width="..." height="..." />

6)最终存储包含嵌入图像的完整HTML。

6) finally store complete HTML with embedded images as you want.

这篇关于是否可以缓存加载在iPhone UIWebView中的资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆