javascript - Save or destroy data/DOM elements? Which takes more resources? -


i've been getting more , more high-level application development javascript/jquery. i've been trying learn more javascript language , dive of more advanced features. reading article on memory leaks when read section of article.

javascript garbage collected language, meaning memory allocated objects upon creation , reclaimed browser when there no more references them. while there nothing wrong javascript's garbage collection mechanism, @ odds way browsers handle allocation , recovery of memory dom objects.

this got me thinking of coding habits. time have been very focused on minimizing number of requests send server, feel practice. i'm wondering if don't go far. unaware of any kind of efficiency issues/bottlenecks come javascript language.

example

i built impound management application towing company. used jquery ui dialog widget , populated datagrid specific ticket data. now, sounds simple @ surface... lot of data being passed around here.

(and question... drumroll please...)

i'm wondering pros/cons each of following options.

1) make one request given ticket , store permanently in dom. showing/hiding modal window, means 1 request sent out per ticket.

2) make request every time ticket open , destroy when it's closed.


my natural inclination store tickets in dom - i'm concerned start hog ton of memory if application goes long time without being reset (which be).

i'm looking pros/cons both of 2 options (or neat haven't heard of =p).

the solution here depends on specifics of problem, 'right' answer vary based on length of time page left open, size of dom elements, , request latency. here few more things consider:

  • keep newest n items in cache. works if redisplay items in short period of time.
  • store data each element instead of dom element, , reconstruct dom on each display.
  • use html5 storage store data instead of dom or variable storage. has added advantage data can stored across page requests.

any caching strategy need consider when invalidate cache , re-request updated data. depending on strategy, need handle conflicts result multiple editors.

the best way started using simplest method, , add complexity improve speed necessary.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -