【问题标题】:Performance issue in phonegap and Jquery mobilephonegap 和 Jquery mobile 中的性能问题
【发布时间】:2014-10-06 20:57:11
【问题描述】:

我在 phonegap 3.0 中遇到了一些性能问题。我有两个 html 页面(我不想放在一起作为一页)。这两个页面都调用了 jquery mobile script 和 phonegap 的 deviceready 函数。我使用诸如window.location =“page2.html”之类的导航命令。

它可以转到page2.html,但需要7秒(我认为它再次加载了脚本文件)。所以我尝试使用 window.location.href="page2.html"。它会在 1 秒内立即转到 page2,但不能在 page2 中调用页面加载函数(又名:$(document).ready())。

我应该如何解决这个问题?感谢您的任何建议或帮助!

已编辑:

page1.html 头文件功能

<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/jquery.mobile-1.1.1.min.js"></script>
<script type="text/javascript" src="js/less-1.3.0.min.js"></script>

<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/themes/default/jquery.mobile.structure-1.1.1.min.css" />
<link rel="stylesheet/less" href="css/style.css">
    <div>
    Please click here to <a style="font-weight:bold;font-size:13px;color:blue;" id="registerButton"  
onclick="callanotherpage('page2.html');" >REGISTER</a> !
    </div>

<script type="text/javascript">    
$(document).ready(init);

function init(){
    document.addEventListener("deviceready", function(){
         },true);

      $("#pageLoader").hide();

}

function callanotherpage(page_name){
    window.location.replace(page_name);
  }

在page2.html中

<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="js/jquery.mobile-1.1.1.min.js"></script>
    <script type="text/javascript" src="js/less-1.3.0.min.js"></script>

    <link rel="stylesheet" href="css/reset.css">
    <link rel="stylesheet" href="css/themes/default/jquery.mobile.structure-1.1.1.min.css" />
    <link rel="stylesheet/less" href="css/style.css">
<script type="text/javascript">    
    $(document).ready(init);

    function init(){
        document.addEventListener("deviceready", function(){
             },true);

          $("#pageLoader").hide();

    }

    function callanotherpage(page_name){
        window.location.replace(page_name);
      }

</script>

最佳 Rgds, 箭蛙

【问题讨论】:

    标签: javascript jquery-mobile cordova


    【解决方案1】:

    只使用普通链接怎么样?

    <a href="page2.html">link</a>
    

    我在 3 个不同的 html 页面上有一个包含 9000 行代码的应用程序。每页有9000多行。从一个站点到另一个站点的更改不会超过

    【讨论】:

    • 您好兄弟,您使用的是PhoneGap 3.x 吗?
    • 不,我使用的是 Cordova 3.5。如果您想知道如何开始使用,您可以查看 Cordova CLI 指南。我更喜欢科尔多瓦,但那是你的选择,你想做什么。 cordova.apache.org/docs/en/3.5.0/…
    • 嗨,兄弟,但是当我使用 window.location.href = "page2.html" 时,它可以运行不到一秒。但它不会被称为page2.html 的页面加载函数。还在纠结??
    • Dartfrog 一些代码呢?
    • 嗨 Sithys,我解决了 rdy。这是因为 javascript 文件,less-1.3.0.min.js。感谢您的宝贵时间。
    【解决方案2】:

    尝试使用

    document.location = "page2.html";
    

    【讨论】:

      猜你喜欢
      • 2013-07-31
      • 1970-01-01
      • 1970-01-01
      • 2014-08-21
      • 2012-01-02
      • 2012-03-14
      • 1970-01-01
      • 1970-01-01
      • 2013-03-19
      相关资源
      最近更新 更多