从服务器到Javascript获取数据的最快方法
因此,我正在开发的程序允许用户使用WebGL、JIT等查看各种数据的不同Javascript实现的图形表示。服务器端是用python编写的,并使用cherrypy和genshi+buffet 问题是许多文件都非常大,实际数据到达Javascript所需的时间开始成为一个问题 目前的方法是使用服务器端公开的cherrypy方法:从服务器到Javascript获取数据的最快方法,javascript,python,cherrypy,Javascript,Python,Cherrypy,因此,我正在开发的程序允许用户使用WebGL、JIT等查看各种数据的不同Javascript实现的图形表示。服务器端是用python编写的,并使用cherrypy和genshi+buffet 问题是许多文件都非常大,实际数据到达Javascript所需的时间开始成为一个问题 目前的方法是使用服务器端公开的cherrypy方法: @cherrypy.expose @logged() def read_server_file(self, coded_path): """ Retri
@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;
}
所以我的问题是,你知道有什么更快/更有效的方法来获取所需的数据吗
问候,,
Bogdan使用staticdir工具。请参见大多数Web服务器都应该有一个选项,可以直接为静态文件提供服务,而无需经过webapp层。我不知道这是否会对你的情况产生很大影响,但值得注意。