Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Javascript run so slow on iPhone?

I've been researching writing an app for iPhone. I really like the look of PhoneGap which basically allows you to contain a webpage in an app. My skills are primarially in HTML/Javascript so this tool allows me to make the most of my skills without having to spend many hours learning how to write an app natively for the iPhone.

I've been doing some tests on my iPhone for Javascript, and some seemingly simple examples run painfully slow. Really slow. This unfortunatly is a big problem for my task!

Any work arounds? If I want to do anything interesting am I going to have to write a 'proper' app?

An explanation on why Apple have seemingly created such a bad implementation of Javascript would be interesting as well (possibly to make more money? Less web apps = more apps in the store?)

References

http://ajaxian.com/archives/ipad-javascript-shockingly-slow

like image 859
Tom Gullen Avatar asked Jul 22 '10 10:07

Tom Gullen


2 Answers

Javascript is not particularly slow, but the DOM is very slow.
I think it is the same as a desktop browser, but magnified.
I would check first all DOM manipulations, if they can't be optimized.

Another option, is to use a templating engine.
The main DOM manipulations are done through innerHTML injection, which is fast even on mobiles.

We've built a mobile version of our web app, and we use PURE (an open source JS lib we created) to render the HTML from JSON data, and it is very responsive.

We went the HTML5 way(not native) but I think generating the HTML could be done the same way when wrapped in PhoneGap.

like image 72
Mic Avatar answered Sep 22 '22 12:09

Mic


I don't think Apple has created any special implementation of Javascript for Mobile Safari. Probably it's the same as or very similar to the desktop Safari.

These devices are small and have strict power constraints, so the CPU is slow.

like image 20
unbeli Avatar answered Sep 22 '22 12:09

unbeli