有没有办法让UIWebView更快

时间:2022-01-10 18:06:11

I have a local HTML page which doesn't has any external link(css or images..)

我有一个本地HTML页面,它没有任何外部链接(css或图像)。

I use method below to load it to a WebView

我使用下面的方法将它加载到WebView中

- (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)textEncodingName baseURL:(NSURL *)baseURL;

it takes around 5-8 seconds to load this page, that's too slow. right?

加载这个页面大约需要5-8秒,太慢了。对吧?

but when I load that page in iPhone safari, it takes around 2 second.

但是当我在iPhone safari中加载这个页面时,大约需要2秒。

I don't know why it is slow like that in my WebView.

我不知道为什么在我的WebView中它是如此的慢。

I also did a Google search, but I couldn't find any answer.

我也做了谷歌搜索,但是我找不到任何答案。

2 个解决方案

#1


0  

To load local html file you should try this:

要加载本地html文件,您应该尝试以下方法:

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]isDirectory:NO]]];

#2


0  

If you have the HTML as text then use the loadHTML:

如果HTML是文本,请使用loadHTML:

[webView loadHTMLString:@"<html><body>Some HTML</body></html>" baseURL:nil];

It loads about 2 seconds for me (simple HTML).

它为我加载大约2秒(简单的HTML)。

Maybe you have some very large HTML and you read it from file?

也许你有一些很大的HTML然后你从文件中读取它?

#1


0  

To load local html file you should try this:

要加载本地html文件,您应该尝试以下方法:

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]isDirectory:NO]]];

#2


0  

If you have the HTML as text then use the loadHTML:

如果HTML是文本,请使用loadHTML:

[webView loadHTMLString:@"<html><body>Some HTML</body></html>" baseURL:nil];

It loads about 2 seconds for me (simple HTML).

它为我加载大约2秒(简单的HTML)。

Maybe you have some very large HTML and you read it from file?

也许你有一些很大的HTML然后你从文件中读取它?