如何在 Webkit 中增量加载 html?
我有大量的 XHTML 内容,我想在 WebKit 中显示。不幸的是,Webkit 运行在硬件速度相当慢的移动平台上,因此一次加载一个大的 HTML 文件非常慢。因此我想逐渐加载 HTML 内容。我已将数据分成小块,并正在寻找将其输入 WebKit 的正确方法。
大概我会使用javascript?通过 javascript 执行此操作的正确方法是什么?我正在尝试 document.body.innerHTML += '一些数据'。这似乎没有多大作用 - 可能是因为我的块可能不是有效的独立 html。我也尝试过 document.body.innerText += '一些数据'。这似乎不起作用。
有什么建议吗?
I have a large amount of XHTML content, that I would like to display in WebKit. Unfortunately, Webkit is running on a mobile platform with fairly slow hardware, so loading a large HTML file all at once is REALLY slow. Therefore I would like to gradually load HTML content. I have split my data in small chunks and am looking for the proper way to feed it into WebKit.
Presumably I would use javascript? What's the right way of doing it through javascript? I'm trying document.body.innerHTML += 'some data'. Which doesn't seem to do very much - possibly because my chunks may not be valid standalone html. I've also tried document.body.innerText += 'some data'. Which doesn't seem to work.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这听起来像是基于 Ajax 的“惰性”内容加载的完美候选者,它在用户向下滚动页面时开始加载内容。有几个 jQuery 插件可以实现此目的。 这就是其中之一。
不过,无论如何,您都必须为此拥有有效的块。另外,我不确定您的硬件对此有何反应。如果问题出在 RAM 或硬盘内存上,则无论您如何加载数据,都可能会遇到相同的问题。只有当它是实际连接或页面加载速度时,延迟加载才有意义。
This sounds like a perfect candidate for Ajax based "lazy" content loading that starts loading content while the user scrolls down the page. There are several jQuery plugins for this. This is one of them.
You will have to have valid chunks for this in any case, though. Also, I'm not sure how your hardware is going to react to this. If the problem is RAM or hard disk memory, you may encounter the same problems no matter how you load the data. Only if it's the actual connection or the speed at which the page is loaded, will lazy loading make sense.
根据需要通过 ajax 加载它。我有类似的情况,当用户滚动到页面末尾附近时,它会加载另外 50 个条目。由于每个条目包含很多js事件,太多条目会降低性能;因此,在 200 条记录之后,当用户滚动时,我从列表的另一端删除 50 条记录。
无需重新发明轮子。使用 jQuery 的 ajax 方法(以及许多速记变体): http://api.jquery.com /类别/ajax/
Load it as needed via ajax. I have a similar circumstance, and as the user scrolls near the end of the page, it loads another 50 entries. Because each entry contains many js events, too many entries degrades performance; so after 200 records, I remove 50 from the other end of the list as the user scrolls.
No need to reinvent the wheel. Use jQuery's ajax method (and the many shorthand variantes out there): http://api.jquery.com/category/ajax/