Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript on ipad loads slow

I have a basic html site (html5 , JavaScript, jQuery) that I have running on an iPpad2. I do basic testing with a Google Chrome, just to test layout images and copy etc. My real test however needs to be on an actual iPad.

On the iPad, my code seems to have a 2-4 second delay as compared to Chrome which loads instantly. I have been unable to find the bottleneck. I added alerts at various points in the code, but all the alerts appear immediately, one after the other and it seems the delay occurs after the last alert which is at the last line of code.

The alerts may be misleading as maybe the code is cached before its executed? Is there something I should look for or avoid in my code in order to speed things up on the iPad?

like image 307
Mike6679 Avatar asked May 31 '12 22:05

Mike6679


1 Answers

If you do not cache your selector results - mobile devices are susceptible to poor performance

what I mean is if you do this:

$("#someId").css(some, stuff);
$("#someId").css(other, stuffs);
$("#someId").attr(even, more);

compared to

var ourElement = $("#someId");
ourElement.css(some, stuff);
ourElement.css(other, stuffs);
ourElement.attr(even, more);

now if you are doing the prior "in the real world" - in loops, etc.. - it can amount to a huge performance detriment to mobile devices

good luck

like image 72
Brandt Solovij Avatar answered Sep 29 '22 18:09

Brandt Solovij