How fast typical PhoneGap app can be started? Tips to speed up?

后端 未结 2 1582
别那么骄傲
别那么骄傲 2020-12-13 05:24

I wonder how fast you could make simple PhoneGap app loaded. My simple app takes 6-8 seconds on Galaxy S3 (all resources are stored in local drive). Not sure whether it is

2条回答
  •  轮回少年
    2020-12-13 06:02

    You Can increase speed of app by:
    1. Using minified versions of js which you have included in you project.
    2. Avoid using images with bigger size. tune them with web compatible PNG files Optimize Images Use CSS Sprite Sheets enter image description here

       .icon {
          width: 14px; height: 14px;
          background-image: url("glyphicons-halflings.png");
        }
        .icon-glass {
          background-position: 0 0;
        }
        .icon-music {
          background-position: -24px 0;
        }
        .icon-search {
          background-position: -48px 0;
        }
    

    Use the right image size (don't scale images in HTML) Host images on scalable, distributed systems (i.e. S3) Avoid 404s for images

    
    


    3. Avoid using much of CSS.Limit Shadows and Gradients link box-shadow,border-radius,gradients,text-align Try disabling some of the CSS that slows it down. In your jquery mobile .css file add this to the bottom:

    * {
    text-shadow: none !important;
    -webkit-box-shadow: none !important;
    -webkit-border-radius:0 !important;
    -webkit-border-top-left-radius:0 !important;
    -webkit-border-bottom-left-radius:0 !important;
    -webkit-border-bottom-right-radius:0 !important;
    -webkit-border-top-right-radius:0 !important;
    }
    


    4. Use CSS Transitions + Hardware Acceleration Use Native Scrolling
    5. If you are using any Live url to get JS better download them and use locally.
    6. FastClick FastClick is a simple, easy-to-use library for eliminating the 300ms delay between a physical tap and the firing of a click event on mobile browsers.

    7. use Slpash screen.
    8. Avoid using framework use only if necessary. Try to make responsive design.
    9. Don't generate the UI on the server.Create the UI in JavaScript at the client-side
    10. Minimize Reflows

    • Reduce the number of DOM elements.
    • Minimize access to the DOM Update elements "offline" before reinserting into DOM.
    • Avoid tweaking layout in JavaScript

    slow

    $("#header a.back").on("click", clickHandler);
    $("#header a.back").css("color", "white");
    $("#header a.back").css("text-decoration", "none");
    $("#header a.back").attr("href", "#");
    

    Fast

    var $backButton = $("#header a.back");
    $backButton.on("click", clickHandler);
    $backButton.css("color", "white");
    $backButton.css("text-decoration", "none");
    $backButton.attr("href", "#");
    


    11. Avoid Network Access Dont make network dependend apps for getting content

    $.ajax({url: "services/states"}).done(function(data) {
        states = data;
    });
    

    use Cache Static Data LocalStorage, Database & File slow

    $.ajax({url: "slow/feed"}).done(function(data) {
    
    });
    

    fast

    dataAdapter.getItems().done(function(data) {
    
    });
    


    12. Don't wait for the data to display the UI

    // Display view
    displayView();
    
    // Get data
    $.ajax({url: "product/101"}).done(function(product) {
        // Update view
    });
    

提交回复
热议问题