单页应用程序 - 是否在DOM中保留页面(视图)?

时间:2015-11-11 13:47:38

标签: javascript dom jquery-mobile backbone.js marionette

我正在构建一个移动网络应用,并考虑管理应用页面的最佳方法(比如说全屏视图')。

使用jQuery Mobile时,大量使用的页面都保存在DOM中。其他一些框架(Backbone / Marionette)用户suggest只有一个页面被拆分为导航更新的区域。由于我的页面之间没有太多共享(即使页眉/页脚更改),这意味着如果之前删除了整个页面应该在导航时重新呈现。

通过快速使用这两种方法,我注意到DOM中已经缓存的页面比再次渲染它更快,而且在保持页面更长时间的情况下我没有感觉到性能问题。

我的问题是,您的经历中最好的方法是什么?如果页面内容没有太大变化或根本没有变化,那么也许我不应该删除视图。 (我说的是最多10个中等重量的页面)。干杯

1 个答案:

答案 0 :(得分:0)

I believe the conventional thing to do (and usually the most performant) is to only render enough content to fill the page. If the content cannot be seen, there is little use having it in the DOM.

However, just because that might be the conventional thing to do doesn't mean that it is the best thing for your app. If you are able to achieve noticeably better performance keeping all your content in the DOM then I do not see that as a bad approach.

You may be experiencing performance issues with the conventional approach because you do not have the experience or know-how to improve that approach yet, but you will learn those tricks eventually and that may be the best time to switch to the conventional approach over your more performant approach.