带有jQuery Mobile的cordova / phonegap启动太慢

哈姆扎尔

我正在使用最新版本的cordova(phonegap),我的想法是:显示从我启动应用程序开始到加载过程完成的加载页面(在deviceready上,从API等获取帖子),然后隐藏加载页面并向用户显示索引。我面临的问题是应用程序的启动速度太慢,并且加载页面仅显示1秒钟,即使应用程序未完成加载过程也消失了(前3秒钟我出现黑屏)。这是我的代码:Index.html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="msapplication-tap-highlight" content="no" />
        <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/jquery.mobile-1.4.0.css" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <title>Hello World</title>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/jquery.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script type="text/javascript" src="js/jqmobile.js"></script>
    </head>
    <body>
    <div data-role="page" id="loading">
    <span id="loading_container">
    	<div class="mini_logo"></div>
    	<div class="loading"></div>
    </span>
    </div>
  <div data-role="page" class="hide" id="index" data-cache="never">
    <div data-role="panel" id="panel" data-position="right" data-theme="a" data-display="push"  data-position-fixed="true">
    <div id="logo"></div>
    <div id="socialnetworks">
    <a href="#" class="linkedin"></a>
    <a href="#" class="youtube"></a>
    <a href="#" class="gplus"></a>
    <a href="#" class="twitter"></a>
    <a href="#" class="facebook"></a>
    </div>
    <ul id="menuIcons">
    <li><a href="index.html" rel="external">الرئيسية</a></li>
    </ul>
    
    
    </div>

    <div data-role="header" data-position="fixed">
      <a data-iconpos="notext" href="#panel" data-role="button" data-icon="bars" class="ui-nodisc-icon" style="background:transparent !important; border:0 !important; box-shadow:none !important;margin:3px 3px 0 0 !important"></a>
      <h1>News</h1>
      <a data-iconpos="notext" href="javascript::void(0)" id="refresh" data-role="button" data-icon="refresh" class="ui-nodisc-icon" style="background:transparent !important; border:0 !important; box-shadow:none !important;margin:3px 3px 0 0 !important"></a>
    </div>

    <div data-role="content" role="main" id="posts_list">
    </div>
  </div>
    </body>
</html>

我的index.js文件:

var serviceURL = "http://somesite.com/wordpress/?json=";
//THIS CODE SHOULD BE PART OF A FILE WHICH IS LOADED BEFORE jQueryMobile

/**
* Create couple of jQuery Deferred Objects to catch the 
* firing of the two events associated with the loading of
* the two frameworks.
*/
var gapReady = $.Deferred();
var jqmReady = $.Deferred();
var categoriesReady = $.Deferred();
var postsReady = $.Deferred();

//Catch "deviceready" event which is fired when PhoneGap is ready
document.addEventListener("deviceReady", deviceReady, false);

//Resolve gapReady in reponse to deviceReady event
function deviceReady()
{
	gapReady.resolve();
}

/**
* Catch "mobileinit" event which is fired when a jQueryMobile is loaded.
* Ensure that we respond to this event only once.
*/
$(document).one("mobileinit", function(){
	$.mobile.page.prototype.options.domCache = false;
	jqmReady.resolve();
});

/**
* Run your App Logic only when both frameworks have loaded
*/
$.when(gapReady, jqmReady,getCategoriesList(),getData()).then(init);

function getCategoriesList(){
	$.getJSON(serviceURL + 'get_category_index', function(data) {
		cats = data.categories;
		$.each(cats, function(index, cat) {
			$("#menuIcons").append('<li><a data-ajax="false" href="category.html?id='+cat.id+'">'+cat.title+'</a></li>');
		});
	});
	categoriesReady.resolve();
}
// App Logic
function init()
{
	$('#index').removeClass('hide');
	 $(':mobile-pagecontainer').pagecontainer('change', '#index', {
        transition: 'flip',
        changeHash: false,
        reverse: true,
        showLoadMsg: false
    });
	
}
function getData() {
	$.getJSON(serviceURL + 'get_recent_posts&page=1', function(data) {
		posts = data.posts;
		$.each(posts, function(index, post) {
			id = post.id;
			title = post.title;
			thumb = post.thumbnail;
			comments = post.comment_count;
			author  = post.author['name'];
			  $('#posts_list').append('<a href="post.html?id='+id+'" data-ajax="false"><div class="single-post">'
			  +'<div class="img"><img data-original="'+thumb+'" class="lazy" title="" /></div>'
			  +'<div class="info">'
			  +'<div class="title">'+title+'</div>'
			  +'<div class="stats"><span class="author">'+author+'</span> <span class="comments">'+comments+' comments </span></div>'
			  +'</div>'
			  +'</div></a>');
		});
	});
	
	postsReady.resolve();
}

请任何人能给我一些建议以实现我的主要目标吗?张贴例子会很棒。

姓名

当phonegap应用程序启动时,第一件事就是加载cordava。因此,此时您无法使用JavaScript代码执行任何操作,此时您将看到启动画面。几秒钟后它将消失,但是您可以通过在config.xml中进行设置来防止这种情况:

<preference name="AutoHideSplashScreen" value="false" />

现在,您需要手动隐藏它,您可以通过在设备就绪中放置以下行来实现此目的,例如:

navigator.splashscreen.hide()

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

jQuery Mobile Phonegap Cordova事件无法正常工作并触发

来自分类Dev

jQuery mobile $ .mobile.changePage()Windows Phone 8无法正常工作Cordova / PhoneGap

来自分类Dev

jQuery mobile $ .mobile.changePage()Windows Phone 8无法正常工作Cordova / PhoneGap

来自分类Dev

jQuery Mobile太慢

来自分类Dev

使用PhoneGap Cordova的jQuery-Mobile And CSS无法为Android工作/加载吗?

来自分类Dev

在带有phonegap的jQuery mobile中链接页面/加载javascript的最佳实践是什么?

来自分类Dev

带有phonegap的棘轮push.js(cordova)

来自分类Dev

带有phonegap的棘轮push.js(cordova)

来自分类Dev

带有Google Apps脚本的JQuery Mobile

来自分类Dev

带有错误的带有重音符号的字符,并通过Phonegap / Cordova进行确认

来自分类Dev

PhoneGap + jQuery Mobile

来自分类Dev

删除iOS PhoneGap / Cordova –启动屏幕控件

来自分类Dev

带有phonegap的sencha touch 2.3仅默认图标/启动

来自分类Dev

带有Cordova的iOS上的jQuery .text()无法正常工作

来自分类Dev

jQuery Mobile和PhoneGap有什么区别

来自分类Dev

Phonegap + jQuery Mobile + Backbutton + Pageinit

来自分类Dev

Cordova-jQuery Mobile图标低分辨率

来自分类Dev

带有JSON和jQuery Mobile的多级列表菜单

来自分类Dev

带有IScrollView的Jquery Mobile页面中的GMap

来自分类Dev

带有ASP.NET和SQL Server的jQuery Mobile

来自分类Dev

在带有谷歌地图的jquery mobile中添加轮播

来自分类Dev

带有滑动过渡的jQuery mobile更改页面

来自分类Dev

带有列表视图的jQuery Mobile奇怪行为

来自分类Dev

带有REST / Web API服务的Cordova / Phonegap应用程序的SVN和TFS结构

来自分类Dev

带有PhoneGap Build 6.0.0版本的Cordova WKWebView插件

来自分类Dev

带有jQuery函数的Anchor标签不会多次启动

来自分类Dev

Phonegap Cordova-如何删除默认启动屏幕?

来自分类Dev

Phonegap / Cordova没有显示初始屏幕

来自分类Dev

没有Phonegap版本的Phonegap / Cordova到ipa文件

Related 相关文章

  1. 1

    jQuery Mobile Phonegap Cordova事件无法正常工作并触发

  2. 2

    jQuery mobile $ .mobile.changePage()Windows Phone 8无法正常工作Cordova / PhoneGap

  3. 3

    jQuery mobile $ .mobile.changePage()Windows Phone 8无法正常工作Cordova / PhoneGap

  4. 4

    jQuery Mobile太慢

  5. 5

    使用PhoneGap Cordova的jQuery-Mobile And CSS无法为Android工作/加载吗?

  6. 6

    在带有phonegap的jQuery mobile中链接页面/加载javascript的最佳实践是什么?

  7. 7

    带有phonegap的棘轮push.js(cordova)

  8. 8

    带有phonegap的棘轮push.js(cordova)

  9. 9

    带有Google Apps脚本的JQuery Mobile

  10. 10

    带有错误的带有重音符号的字符,并通过Phonegap / Cordova进行确认

  11. 11

    PhoneGap + jQuery Mobile

  12. 12

    删除iOS PhoneGap / Cordova –启动屏幕控件

  13. 13

    带有phonegap的sencha touch 2.3仅默认图标/启动

  14. 14

    带有Cordova的iOS上的jQuery .text()无法正常工作

  15. 15

    jQuery Mobile和PhoneGap有什么区别

  16. 16

    Phonegap + jQuery Mobile + Backbutton + Pageinit

  17. 17

    Cordova-jQuery Mobile图标低分辨率

  18. 18

    带有JSON和jQuery Mobile的多级列表菜单

  19. 19

    带有IScrollView的Jquery Mobile页面中的GMap

  20. 20

    带有ASP.NET和SQL Server的jQuery Mobile

  21. 21

    在带有谷歌地图的jquery mobile中添加轮播

  22. 22

    带有滑动过渡的jQuery mobile更改页面

  23. 23

    带有列表视图的jQuery Mobile奇怪行为

  24. 24

    带有REST / Web API服务的Cordova / Phonegap应用程序的SVN和TFS结构

  25. 25

    带有PhoneGap Build 6.0.0版本的Cordova WKWebView插件

  26. 26

    带有jQuery函数的Anchor标签不会多次启动

  27. 27

    Phonegap Cordova-如何删除默认启动屏幕?

  28. 28

    Phonegap / Cordova没有显示初始屏幕

  29. 29

    没有Phonegap版本的Phonegap / Cordova到ipa文件

热门标签

归档