English 中文(简体)
记忆与 快速网络应用
原标题:Memory versus Speed in Javascript Web Applications

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.

为了取得最佳效果,我想得到更好的理解,并想提出两个问题:

  1. 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?
  2. 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

问题回答

Cache everything (that might be used more than once) . (write to Canvas/ImageData). You should only have 1 copy of the framework in memory. If you re concerned there s more, rewrite it to force all AMDs to use a single source Backbone.

Memory is speed.

If you want better speed:

  • extern your js files for browser caching.
  • Use localstorage
  • Do most computation at the user
  • Minimize the server and streamline request flow




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签