从服务器获取数据到Javascript的最快方法

时间:2011-11-18 12:37:32

标签: javascript python cherrypy

因此,我正在开发的程序使用户可以查看各种数据的不同Javascript实现的图形表示(使用WebGL,JIT等)。服务器端是用python编写的,使用带有genshi + buffet的cherrypy。

问题是许多文件非常庞大,实际数据到达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 个答案:

答案 0 :(得分:0)