KingPolygon
KingPolygon

Reputation: 4755

iOS: Fastest way to load and inject javascript into a webpage?

What is the fastest way to inject javascript into a webpage and run the script? Is there any way where I can load the webView without images to speed up load times in iOS? I came across the javascriptcore framework, but I'm not really sure if that will help.

Any help would be greatly appreciated.

Upvotes: 0

Views: 217

Answers (2)

2intor
2intor

Reputation: 1044

you should use UIWebview's delegate methods like following to achieve your purpose ,

1) What is the fastest way to inject javascript into a webpage and run the script?

use below delegate method this method is called first when webview has completed its loading,

- (void)webViewDidFinishLoad:(UIWebView *)theWebView 
{
  //use this methods to run javascript 
  [theWebView stringByEvaluatingJavaScriptFromString:@"your javascript here"];
}

2) Is there I way where I can load the webView without images to speed up load times in ios?

use below method to stop loading images like below,

- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
  //check here if [[[request URL] absoluteString] rangeOfString:".png"] range of ".png,.jpeg,.jpg" is available then return NO; else return YES;
}

Upvotes: 1

RobertoNovelo
RobertoNovelo

Reputation: 3819

I am not sure if this is what you need, but here you go!:

It's possible to present images as part of the background, called up through CSS. If you've got an image that's 200px by 100px you can use the following HTML code:

<div class="pretty-image"></div>

And this CSS:

.pretty-image 
{ 
background: url(filename.gif); 
width: 200px; 
height: 100px 
}

This may at first seem a little pointless but this technique could really improve the download time of your pages. Browsers basically download background images after everything else. By using this technique, your text will load instantaneously and your site users can freely roam about the page while your 50kb fancy image downloads.

This technique disables the ALT attribute though so if you really want to have one then replace the above HTML code with this:

<image src="spacer.gif" class="pretty-image" alt="description" />

Spacer.gif is a 1px x 1px transparent image. Now you have a 50 byte transparent image and the main content loading first, and your great big decorative image, complete with ALT text, loading second. Perfect.

Please note that this technique is only good for decorative images and not informational ones. Any user who has CSS disabled will not be able to see your CSS-embedded images (or their alternative text).

source: http://www.webcredible.co.uk/user-friendly-resources/web-usability/speed-up-download-time.shtml

Upvotes: 0

Related Questions