简体   繁体   English

如何减少phonegap应用程序中外部页面加载的响应时间?

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

I have developed a application for android using phonegap. 我已经开发了一个使用phonegap的android应用程序。 I am loading external HTML pages using XMLHttpRequest . 我正在使用XMLHttpRequest加载外部HTML页面。 It is working fine but it takes time when i loading the external pages. 它工作正常,但加载外部页面需要时间。 How can i reduce the page loading time ? 如何减少页面加载时间? My code as follows : 我的代码如下:

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); 
}

From reading the comments, you are using an offine mobile application, and the external pages are actually local pages bundled with the app. 从阅读评论开始,您使用的是移动应用程序, external页面实际上是与应用程序捆绑在一起的本地页面。 So network latency is not your issue. 因此,网络延迟不是您的问题。

If this is not the case, try including the pages in your www folder. 如果不是这种情况,请尝试在www文件夹中包含这些页面。

Assuming you have done that, one idea is to make your app be a single page and manipulate accordingly. 假设你已经这样做了,一个想法就是让你的应用程序成为一个页面并进行相应的操作。

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

Then in javascript 然后在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