Ajax 如何减少数据表加载时间?
我正在使用数据表插件。最初我尝试的是从一个平面文本文件更新数据表插件。文本文件如下所示Ajax 如何减少数据表加载时间?,ajax,datatables,indexeddb,Ajax,Datatables,Indexeddb,我正在使用数据表插件。最初我尝试的是从一个平面文本文件更新数据表插件。文本文件如下所示 { "data":[ { "reference":"#VIP-123", "application":"Development Aspects", "applicationType":"Current Application" }, { "reference":"#VIP-
{
"data":[
{
"reference":"#VIP-123",
"application":"Development Aspects",
"applicationType":"Current Application"
},
{
"reference":"#VIP-123",
"application":"Development Aspects",
"applicationType":"Current Application"
}
]
}
我在这里面有一个HTML文件,我正在编写JavaScript,如下所示
$(document).ready(function() {
var table=$('#app-table').DataTable( {
"bProcessing": true,
"bPaginate":true,
"bServerSide": false,
"sAjaxSource": "./data/arrays.txt",
"deferRender": true,
"columns": [
{ "data": "reference" },
{ "data": "application" },
{ "data": "applicationType" },
],
"order": [[ 3, "desc" ]],
"ordering": true,
"bFilter": true
} );
数据表呈现良好,直到我的表中没有超过20000行。随着表中的行数增加,数据表的加载时间也会增加
通过使用多个站点,我注意到我们可以通过使用服务器端处理来减少加载时间,为此,我需要使用一个服务器,这在我的情况下是不可能的,因为我是从一个平面文本文件渲染数据。然后我想寻找静态数据存储
所以问题是使用indexedDB我们能解决性能问题吗?如果答案是肯定的,那么有人能告诉我如何解决吗
我能够使用indexedDB,但无法与jQuery数据表集成。我的意思是我需要在JavaScript中进行更改。如果我们可以使用indexedDB进行服务器端处理,那么脚本将是什么?首先以以下方式读取本地文件:
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false);
rawFile.onreadystatechange = function ()
{
if(rawFile.readyState === 4)
{
if(rawFile.status === 200 || rawFile.status == 0)
{
var allText = rawFile.responseText;
}
}
}
然后,使用JQuery将所有文本解析为JSON
请参阅解析为JSON
现在,使用indexedDB API创建数据库,如下所述:
var request = indexedDB.open("<mention_your_db_name_here");
request.onupgradeneeded = function() {
// The database did not previously exist, so create object stores and indexes.
var db = request.result;
var store = db.createObjectStore("books", {keyPath: "reference"});
var titleIndex = store.createIndex("by_reference", "reference", {unique: true});
// Populate with initial data.
store.put({reference: "#VIP-123", application: "Development Aspects", applicationType: "Current Application"});
};
request.onsuccess = function() {
db = request.result;
};
有关indexedDB API的更多详细信息,请参阅为什么不使用分页?即使加载数据不需要那么长时间,您也可能会用20000行数据杀死大多数浏览器。@jrade,谢谢您的回复。我已经在使用分页。已尝试为每个页面加载30行。Indexeddb在缩放方面没有问题。一定是用法有问题。我的问题是无法将IndexedDB与Jquery数据表集成。我的意思是我需要在JavaScript中进行更改。如果我们可以使用indexedDB进行服务器端处理,那么indexedDB的服务器端脚本将是什么?为了清晰起见,尤其是在学习时,最好使用顺序读写事务,而不是版本更改事务。在OnUpgradeRequired中填充是可能的,但这是一种糟糕的设计模式。