簡體   English   中英

如何減少phonegap應用程序中外部頁面加載的響應時間?

[英]How to reduce the response time of external page loading in phonegap application?

我已經開發了一個使用phonegap的android應用程序。 我正在使用XMLHttpRequest加載外部HTML頁面。 它工作正常,但加載外部頁面需要時間。 如何減少頁面加載時間? 我的代碼如下:

function loadHtmlPage(url){ //url - holds the name of the HTML page
    var xmlhttp = new XMLHttpRequest();     
    xmlhttp.onreadystatechange=function(){
    if(xmlhttp.readyState === 4){           
        document.getElementById("externalpagecont").innerHTML = xmlhttp.responseText;   
    };
    xmlhttp.open("GET", url , true);
    xmlhttp.send(null); 
}

從閱讀評論開始,您使用的是移動應用程序, external頁面實際上是與應用程序捆綁在一起的本地頁面。 因此,網絡延遲不是您的問題。

如果不是這種情況,請嘗試在www文件夾中包含這些頁面。

假設你已經這樣做了,一個想法就是讓你的應用程序成為一個頁面並進行相應的操作。

<!doctype html>
<html>
...
    <div id="page1">....</div>
    <div id="page2">....</div>
...
</html>

然后在javascript中

function loadHtml(id) { /* hide / show / get content / your business needs here */}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM