Javascript 锤炼性能

发布于 2024-09-25 12:09:01 字数 404 浏览 2 评论 0原文

我刚刚开始使用数据表(java 脚本)来处理表格数据,由于 js 我能够使用搜索、每页多少行、排序和分页等功能。 在使用js之前,我只是在表格中显示数据(使用Ajax进行分页),但无法使用上述功能(在这种情况下性能良好)。 现在我使用 jquery.dataTables.js 和 jquery.js 文件作为表结构。但问题是,这严重影响了网站的性能,最初所有脚本都只在一页下,然后 Firefox 给出警告消息“无响应脚本”,然后我只是为表创建了单独的文件,然后我就不再收到此消息消息但性能较差。 我所做的是,从API中获取数据,将其存储到数据库中,然后显示出来,但是js花费了大量时间,有时当有数千条数据时它根本不显示表。
我确实需要使用 js 来表,但无法承受这种糟糕的性能。 有人遇到过这个问题吗?
等待宝贵的建议。

I just started using datatables (java script) for tabular data, due to js I am able to use functionalities like search, how many rows per page, sorting and pagination.
Before using js, I was simply showing data in table(used Ajax for pagination), but unable to use above functionalities (Performance in this case was good).
Now I am using jquery.dataTables.js and jquery.js files for the table structure. But problem is that this has badly hammered the performance of site, initially all the script was under one page only, then firefox was giving warnign message as "Unresponsive Script", then I just created separate file for the table, then I stopped getting this message but poorer performance.
What I do is, fetch data from API, store it into database and then show it, but js is taking lot of time, sometimes it simply doesn't show the table when there is thousands of data.
I really need to use js for table but can't afford this poor performance.
Has somebody got this problem before?
waiting for valuable advice.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懒猫 2024-10-02 12:09:02

您无法在 Javascript 中有效地存储和操作数千行数据。 MySQL 等数据库引擎具有各种 gubbin(索引、缓存),以加快搜索(查询)速度。 Javascript 没有这些,你可以根据需要优化你的存储方法和搜索算法,但你永远无法完成一个有效的解决方案。

分页应该在服务器上。服务器发送给你30行数据,当你想要更多时,你向服务器请求更多;通常以新页面加载的形式用另一组结果替换当前内容,或者以 AJAX 请求的形式将新内容追加/添加到现有内容中。

当您想要搜索数据时,使用 Javascript 适合在页面上的内容(约 10 行)中进行搜索,但要搜索整个数据集,请将查询发送到服务器并让您的数据库引擎完成工作。

You cannot efficiently store and manipulate thousands of rows of data in Javascript. Database engines such as MySQL have all sorts of gubbins (indexes, caches), to speed up searching (queries). Javascript has none of this, and you can optimize your method of storage and searching algorithms as much as you want, but you will never accomplish an efficient solution.

Pagination should be on the server. The server sends you 30 rows of data, when you want more, you request more from the server; usually in the form of either a new page load to replace the current contents with another set of results, or an AJAX request to append/ prepend the new content to the existing.

When you want to search the data, using Javascript is fine for searching within the content you have on the page (~10's of rows), but for searching the whole dataset, send the query to the server and let your database engine do the work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文