Phonegap低性能问题

4

我使用 PhoneGap 和 JqueryMobile 框架构建了一个安卓应用,其中包含多个 HTML 和 JS 页面。

首次加载时间非常长(比本地应用程序慢 5-10 秒),页面导航也太慢了。

从一个屏幕导航到另一个屏幕需要很长时间。

是否有任何提示/教程/技巧来提高速度?对于经常使用的应用,它真的无法使用。

另一个问题是应用程序的内存使用过高(一个简单应用约 50MB)

欢迎分享所有的技巧和提示。


在这里写了几个提示:https://dev59.com/Z2Yr5IYBdhLWcg3wKHIp#14010732。希望能有所帮助。 - Andrei Rosca
2个回答

7

以下是我发现对于慢速设备有帮助的优化技巧:

  • Try changing the default page transition. Many Android devices do not support hardware accelerated features of the handset in the browser, which means that the CSS3 transitions that JQueryMobile tries to use by default are very slow. You can use:

    $.mobile.defaultPageTransition = 'none';
    

    to turn off all of the default transitions.

  • As far as script load time, there is not much you can do besides perhaps examining the individual load times for your dependencies and figuring out alternatives - but you can ensure that your app doesn't look wonky while it loads. Here's a quick hack I use:

    <style type="text/css">
      .doc {display: none;} /* don't show body by default */
    </style>
    
    <body id="main_body" class="doc"> 
    

    Once everything loads, I call

    $("#main_body").removeClass("doc");
    

    to show the application. I use a Javascript preloader (LABjs) in order to ensure all of my dependencies get loaded in order.


关闭 defaultPageTransition 解决了我所有的性能问题。 - jasin_89

2

首先,与其使用像jQuery这样的重型框架,不妨试试xuijs


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接