且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何加速jquery手机/ phonegap?

更新时间:2023-02-26 22:32:10

您可以执行以下操作:


  1. 获取deviceready更快

  2. 使用 YUI Compressor 最小化您的JS代码

  3. 将您的指令码标记移至body标记底部。

已经提到你已经把数据库移出了方程式,这可能需要大量的时间在启动。


I have a small web app. Seven pages, 3.6 KB index.html and 855.5 KB total. The only odd thing i have is a database (~500kb) in Javascript with many lines like:

$.data(db,'Aarstraße',['34236:1','34246:2','34270:4','34290:6',...]);

I tested it on iPod/iPhone and Android (HTC Magic) and it is very slow:

Startup

  • iPhone: 14 seconds
  • Android: 21 seconds

Simple page transition (slide)

  • iPhone: 3-4 seconds
  • Android: 4-6 seconds

How can I make this fast?

I already removed the box shadow.

Update

I remove the database leaving 444.7KB page total. Now it runs faster on Android. Around the same as one iPhone. It still feels very slow.

Update 2

After this question, I switched to the latest jquery mobile build. It improved the page transitions for slow Android devices to ~2 seconds per transition. Release of Version 1.1 will be mid/late February.

There are a few things you can do:

  1. Get to deviceready faster.
  2. Minimize your JS code using YUI Compressor
  3. Move your script tags to the bottom of the body tag.

As you've already mentioned you've moved the database out of the equation which was probably taking a bulk of the time on startup.