2011-11-18 76 views
0

因此,我正在開發的程序爲用戶提供了查看各種數據的不同Javascript實現的圖形表示(使用WebGL,JIT等)的可能性。服務器端是用python編寫的,使用genshi + buffet的cherrypy。從服務器獲取數據到Javascript的最快方法

問題是,許多文件真的很大,實際數據到達Javascript的時間開始成爲一個問題。

到目前爲止,這種方法是有服務器端暴露的CherryPy方法:

@cherrypy.expose 
@logged() 
def read_server_file(self, coded_path): 
    """ 
    Retrieve file from Local storage, having a File System Path. 
    """ 
    try: 
     my_file = open(url2path(coded_path), "rb") 
     result = my_file.read() 
     my_file.close() 
     return result 
    except Exception, excep: 
     self.logger.error("Could not retrieve file from path:" + 
          str(coded_path)) 
     self.logger.exception(excep) 

這只是獲取磁盤上的實際文件,從文件返回數據。而在客戶端:

function getFile(fileName) { 
    oxmlhttp = null; 
    try { 
     oxmlhttp = new XMLHttpRequest(); 
     oxmlhttp.overrideMimeType("text/plain"); 
    } catch(e) { 
     try { 
      oxmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
     } catch(e) { 
      return null; 
     } 
    } 
    if (!oxmlhttp) return null; 
    try { 
     oxmlhttp.open("GET", fileName, false); 
     oxmlhttp.send(null); 
    } catch(e) { 
     return null; 
    } 
    return oxmlhttp.responseText; 
} 

所以我的問題是,你知道任何更快/更有效的方式來獲得所需的數據嗎?

問候, 波格丹

+1

大多數Web服務器都應該有一個選項,可以直接提供靜態文件,而無需通過Web應用程序層。我不知道這是否會對你的情況產生很大影響,但值得注意。 –

回答

相關問題