In my former web applications, when the user had a transition from one "page" (no page reload, just a new div) to another, I just hid the one div for later use and created + showed the new one. When the user returned from address management to events management, I only needed to hide the current div and re-show the already used one. Of course, this needs memory, but is faster.
In my new web application, I use Backbone.js, Require.js and jQuery. All my modules are AMD (jquery 1.7.1, backbone.js 0.5.3-optamd3, ...).
http://lostechies.com/derickbailey/201109/15/zombies-run-managing-page-transitions-in-backbone-apps/” http://lostechies.com/derickbailey/201109/15/zombies-run-managing-page-transitions-in-backbone-apps/ 我现在清理了我的遗体,然后向新的“网页”过渡,并在用户返回时重新印制。
Likewise, regarding requirejs amd modules I used to have a speed over memory strategy: The heart of my web app navigation is in my only router object. If the user selects a "page"/feature for the first time, I load the amd module (it s a backbone.js view object) for it and all its dependencies with the require command and store this resulting view object (with its model object) for later use in an array in the router object. When the user comes back, I take the the stored view object and re-render the view.
I guess I will switch from this behaviour also into always reloading the module (from cache), but I am unsure.
为了取得最佳效果,我想得到更好的理解,并想提出两个问题:
- I have 5 AMD modules. When the user needs a feature, I load and execute a module and get a backbone.js view object as a result, which I store in an array in my router object. Every AMD module has Backbone.js (AMD version) as a dependency. When the user has visited all 5 "pages" and all my 5 view objects are stored in my array, do I have 5 copies of backbone.js in my browser memory since every backbone.js dependency is fetched from cache and executed anew, or has the garbage collector removed it?
- How do other web application developer think about this speed over memory strategy?
CONTINUED Today I found a similar question on stackoverflow (http://stackoverflow.com/questions/7866971/how-does-amd-specifically-requirejs-handle-dependancies-across-multiple-module). The answer was: "It will only be loaded once, both of the above modules will get the same module value ...".
因此,储存已经装载的加执行过的强化模块的成果以供日后使用似乎并不好。
Wolfgang