为什么Javascript在iPhone上运行这么慢? [英] Why does Javascript run so slow on iPhone?

查看:130
本文介绍了为什么Javascript在iPhone上运行这么慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究为iPhone撰写应用程式。我真的很喜欢 PhoneGap 的外观,它基本上允许您在应用中包含网页。我的技能主要是在HTML / Javascript中,所以这个工具让我能够充分利用我的技能,而不必花费很多时间学习如何为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.

我已经在我的iPhone上做了一些测试用于Javascript,和一些看起来很简单的示例跑得很慢。真的慢。这不幸是我的任务的一个大问题!

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?

关于为什么苹果似乎创建了这样一个糟糕的Javascript实现的解释

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?)

参考

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

推荐答案

JavaScript不是特别慢,但是DOM非常慢。 br />
我认为它与桌面浏览器相同,但是放大了。
$
如果无法优化,我会首先检查所有的DOM操作。

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.

另一个选择是使用模板引擎。
主DOM操作通过innerHTML注入完成,即使在手机上也是如此。

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

我们制作了一个移动版的网络应用程序,我们使用 PURE

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.

我们采用HTML5方式(非原生),但我认为生成当在PhoneGap中包装时,HTML可以以相同的方式完成。

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

这篇关于为什么Javascript在iPhone上运行这么慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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