我正在制作一个商店概览页面,每页呈现 +- 20 个产品。我从压缩 (gzip) XML 文件 (*.xml.gz) 中获取数据。这是提要:http : //www.endclothing.com/media/end_feeds/awin_affiliates_eu.xml.gz 每天一次,我使用 PHP 将文件下载到我的服务器并提取 XML 文件。
问题是,解压缩的 XML 文件是 +- 60MB 并且包含超过 50k 的产品。现在,当我尝试从 XML 文件中获取产品并显示它们时,进展非常缓慢。使用我在下面使用的代码显示来自本地 XML 的产品信息大约需要 8 秒:
$.ajax({
type: "GET",
url: 'feeds/awin_affiliates_eu.xml',
cache: true,
dataType: "xml",
error: function (response) {
alert("An error occurred while processing XML file");
console.log('XML reading Failed: ', e);
},
success: function (response) {
var max = 20;
$(response).find("product").each(function (i) {
if (i < max) {
var _pid = $(this).find('pid').text();
var _mpn = $(this).find('mpn').text();
var _colour = $(this).find('colour').text();
var _name = $(this).find('name').text();
var _purl = $(this).find('purl').text();
var _instock = $(this).find('instock').text();
var _brand = $(this).find('brand').text();
var _suitable_for = $(this).find('suitable_for').text();
var _ptype = $(this).find('ptype').text();
var _category = $(this).find('category').text();
var _condition = $(this).find('condition').text();
var _desc = $(this).find('desc').text();
var _currency = $(this).find('currency').text();
var _custom1 = $(this).find('custom1').text();
var _price = $(this).find('price').text();
var _deltime = $(this).find('deltime').text();
var _delcost = $(this).find('delcost').text();
var _imgurl = $(this).find('imgurl').text();
var _alternate_image = $(this).find('alternate_image').text();
$("h2._name").eq(i).text(_name);
$(".price").eq(i).text(_price);
var background_url = "url(" + _imgurl + ")";
$(".panel").eq(i).css("background", background_url);
} else {
return false;
}
});
console.log('done reading file');
}
});
有什么方法可以更快地读取 XML 文件,以便更有效地渲染我的产品?