搜索结果经过匹配后被加载到iframe里,速度慢,哪里改进下,加快点速度?
<html xmlns="http://www.w3.org/1999/xhtml">
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>zhua</title>
<script src="http://www.google.com.hk/jsapi" type="text/javascript"></script>
<script type="text/javascript">
   google.load('search', '1');
    
function cse() {
        var sFormDiv = document.getElementById("searchForm");
        var leftScDiv = document.getElementById("leftSearchControl");
 
        this.leftControl = new google.search.SearchControl();
        this.searchForm = new google.search.SearchForm(true, sFormDiv);
 
        // bind clear and submit functions
        this.searchForm.setOnSubmitCallback(this, cse.prototype.onSubmit);
        this.searchForm.setOnClearCallback(this, cse.prototype.onClear);
 
        // set up for small result sets
        this.leftControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);        var searcher;
        var options;
 
        // configure left control
        // Site Restrict to CSE ID for reviews
        searcher = new google.search.WebSearch();
        options = new google.search.SearcherOptions();
        searcher.setSiteRestriction('017315707308107628641:ldi_rm4utyi');
        //searcher.setUserDefinedLabel("Product Reviews");
        options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
        this.leftControl.addSearcher(searcher, options);
 
        this.leftControl.draw(leftScDiv);
 
        // execute a starter search
this.searchForm.execute("<?php echo $_GET['keyword'];?>");
 
}
cse.prototype.onSubmit = function(form) {
var q = form.input.value;
if (q && q!= "") {
  this.leftControl.execute(q);
}
return false;
}
function OnLoad() {
        new cse();
    }google.setOnLoadCallback(OnLoad, true);</script>
</head>
<body>
<div id="searchForm"></div>
<div id="leftSearchControl" class="search-control"></div>
<script type="javascript">
window.onload = function (){
document.write(document.getElementById("leftSearchControl").innerHTML);
}
</script>
</body>
</html>

解决方案 »

  1.   

    我用Google官网代码测试,速度也不快。
    估计是网速和google API调用数据库的返回时间,有关系。
      

  2.   

    要考虑到Google的服务器现在不在内地,最近的也只是在香港,使用它的API要考虑到这一点
      

  3.   

    先把http://www.google.com.hk/jsapi这个js代码放到自己的本地服务器,这样可以节省一部分时间。因为它是加载在iframe中的,你可以考虑使用ajax异步加载,这样也不会影响整体页面显示。
      

  4.   

    http://www.google.com.hk/jsapi放在本地会报错