How to speedup jquery mobile / phonegap?

柔情痞子 提交于 2019-12-20 09:21:37

问题


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.


回答1:


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.




回答2:


What do you do with jQuery-mobile? It's performance is very poor, you should never call it on elements bigger that required. See this discussion about jquery-mobile for details. It is doing very large number of DOM search operations because it works by modifying the DOM tree. As for my tests, it works too slow even on desktop browser.




回答3:


Try without transitions. Even with jQuery 1.1, the page transitions can be really flickery and slow on an iPhone.

To drop page transitions globally, just add the following to jqm.glocal.config.js

$(document).bind("mobileinit", function(){
  $.mobile.defaultPageTransition="none"
});


来源:https://stackoverflow.com/questions/9003393/how-to-speedup-jquery-mobile-phonegap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!