我现在正在开发一个使用 Jquery 的 Web 应用程序,并且在单个 html 文档上有多个页面。这是通过一系列包裹在
标签中的 data-role="page"
来完成的。
现在,这只是这些“页面”中的 5 个,但我计划有 ~900 个(每个可以审查的项目 1 个)。我的问题是,Jquery 是否会一次加载 html 文件中的所有“页面”?
我在想如果是的话,我以这种方式处理这个网络应用程序是不可行的,因为我将加载 900 个页面,并在加载 html 文件后对数据库进行 900 次调用,以便在每个页面中填充评论。
我想在深入研究这个项目之前我可以先问一下。谢谢大家!
更新
我会知道用户下一步将点击哪里。我做了一些研究,认为我找到了一段我相信可以做到的代码。 astebin.com/JpGW5PqN 第 15-20 行。这可以加载第 50 行 id 为 180336 的 div 吗?我不知道如何检查它是否动态加载!
I am working on a web app right now that uses Jquery and has multiple pages on a single html document. This is done through a series of data-role="page"
s wrapped in <div>
tags.
Right now, that is only 5 of these 'pages' but I plan to have ~900 (1 for every item that can be reviewed). My question is, does Jquery load all the 'pages' in the html file at once onload?
I'm thinking if it does, it isnt feasible for me to go about this web-app this way, as I'll have 900 pages loaded with 900 calls to a database to populate each with reviews as soon as the html file is loaded.
I thought I might ask before I go too far into the project. Thanks all!
UPDATE
I will know where the user will click next. I did some research and think I found a piece of code I believe does it. pastebin.com/JpGW5PqN its line 15-20. Will this work to load the div with id 180336 on line 50? I don't know how to check if it is loaded dynamically or not!
发布评论
评论(2)
因为它仍然是一个简单的 HTML 页面,所以是的,所有这些 DIV 都会在第一次加载时加载。有不同的方法可以实现这一点,但最明显的方法是在需要时使用 $.ajax 加载页面。预加载所有页面将使一切变得非常慢。
您可以做的优化是,在某些情况下,您可能知道用户下一步将单击/导航的位置,并且您可以在用户查看当前内容时预加载该内容。
As it’s still a simple HTML page, then yes, all of those DIV’s are loaded on the first load. There are different ways about going with this, but the most obvious one would be to use $.ajax to load the pages when you need them. Preloading all pages will make everything very slow.
What you can do to optimize, is that in some cases you might know where the user will click/navigate next and you can preload that content while the user is viewing your current one.
就像 margusholland 提到的那样,您可能想对此进行部分加载。否则您将有 900 个 AJAX 请求。
加载 1-10 页,或者在 用户向下滚动时与滚动加载更多页面进行交互 页面。
Like margusholland mentioned, you may want to do partial load on this. Otherwise you have 900 AJAX requests.
Either load 1-10 pages or interact with scroll loading more whenever user scrolls down the page.