Does iUI delete entries from DOM on page back?-

8 views
Skip to first unread message

ltlfrari

unread,
Dec 17, 2009, 2:30:43 PM12/17/09
to iPhoneWebDev
Using iUI 0.40 dev1.
In my app, each click of a link on a page results in a call to the
back end server that sends a new page, complete with unique id, to the
client.
so, I start at screen 1, click a link, go to screen 2, click a link,
go to screen 3 etc. Each click is adding a new page element to the
DOM.
When I click the back button, what happens to those DOM elements, do
they stay in the DOM or does iUI delete them?
My actual app is slightly more complicated than that with bookmarked
divs in the response as well as the main page div, so I've got the
potential for a lot of old markup being left attached to the apps DOM
if iUI is not deleting it.

Thanks all,

Dave E

Remi Grumeau

unread,
Dec 17, 2009, 3:09:17 PM12/17/09
to iphone...@googlegroups.com
Simple answer to the mail subject: yes, iUI deletes entries from the DOM.
Easy way to see it: index.html with a link to page.html. Clic on the link, go back, edit page.html and clic on the link again: the modification is live in iUI. So you don't need to refresh the whole app get an updated content … but no "cache" is made.

If you have some heavy server side operations/queries to render a page, you'd better try to find a solution to generate a cache on the server-side (or even a simple HTML file created by PHP/ASP) : easier to update/manage/upgrade/...
My 0,02€ is client side cache is good for CSS and template-medias but not for the content itself.

Remi

> --
>
> You received this message because you are subscribed to the Google Groups "iPhoneWebDev" group.
> To post to this group, send email to iphone...@googlegroups.com.
> To unsubscribe from this group, send email to iphonewebdev...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/iphonewebdev?hl=en.
>
>


Remi Grumeau
(+33) 663 687 206
http://www.remi-grumeau.com

Sean Gilligan

unread,
Dec 17, 2009, 6:13:34 PM12/17/09
to iphone...@googlegroups.com

> Le 17 d�c. 2009 � 20:30, ltlfrari a �crit :

>
>
>> Using iUI 0.40 dev1.
>> In my app, each click of a link on a page results in a call to the
>> back end server that sends a new page, complete with unique id, to the
>> client.
>> so, I start at screen 1, click a link, go to screen 2, click a link,
>> go to screen 3 etc. Each click is adding a new page element to the
>> DOM.
>> When I click the back button, what happens to those DOM elements, do
>> they stay in the DOM or does iUI delete them?
>>

Elements loaded via AJAX are not deleted unless they are refreshed by
another ajax load. When refreshed by another ajax load the old elements
are replaced by the new elements -- but only if they have the same 'id'
attribute. If you have a long-lived app with a lot of page-frags/views
being loaded you have a potential memory problem. To avoid this you'll
have to find a way to assign a unique id to each element that is
loaded. If it's content from a database you could generate the id from
the record id (e.g. id="widget4039") This will at least reduce the use
of DOM elements to unique records.

iUI could fairly easily be extended to unload DOM elements when no
longer needed (or even to use them as a client side cache) If you are
interested in doing that you should definitely start with the
development versions of iUI 0.40. There is an event mechanism to
support extensions that should make this feature fairly easy to
implement. It is something I would very much like to see. If someone
builds a nice extension with this feature I could easily see that
feature being migrated into the core.

-- Sean


ltlfrari

unread,
Dec 17, 2009, 5:16:13 PM12/17/09
to iPhoneWebDev
Now that I am back home, I just tried this and the answer is no, it
does not.
It does replace an element with the same id if you send it again so
you do see live changes as you describe.
However if I drill down several layers in my app then go back up and
look at the dom in web explorer then the complete dom is still there
with all the elements from where ever I drilled down to.

Fortunately for me, my backend keeps track of the logical level that
the client is at by embedding a level parm into each link. It does
that so that it can generate unique ids for the results divs it
returns.
By capturing the aftertransition event I can run a script to delete
everything from the dom with a level number higher than whatever the
level of the target page is.

I am planning on caching the static stuff (css and scripts) via a
manifest once development is complete (or as complete as it's going to
be). My content is highly volatile and pretty much impossible to cache
although I am considering using a client side database to implement a
'more' function. Send all the data but only display say the first ten
rows, get the next ten from the internal db until user drills down to
next level up up to previous level. Can't do 'more' from the server
because of data volatility.

And to think I am doing this for 'fun!'

Thanks for you input,

Dave E

ltlfrari

unread,
Dec 17, 2009, 9:03:06 PM12/17/09
to iPhoneWebDev
I thought I had replied to this but it seems to have gotten lost.

Anyway, I did some testing and it does not delete the old elements as
you say.
However my apps back end server keeps track of logical level of each
result set as you drill down by appending a parm to each link that
results in a call to it with the current level, then it adds one for
the next level etc.
it does this so that it can create unique ids for the divs in each
result set.
What I did was to use the logical level as a class and added an event
listener for the aftertransition event.
That listener get the class from the target page (event.out = false),
gets the class from it and finds the numeric one.
It then adds one to that value and does a delete of the elements with
that class (class from target page + 1) below the body element (which
is where iUI is attaching all the new divs).

When you are drilling down (increasing level number) the event code
does nothing because there's nothing there to delete. When you are
paging back using the back button the level number is decreasing so
it's continually deleting the previous levels data.

All bit of a fudge and not very generic but it does work.

Sean Gilligan

unread,
Dec 18, 2009, 11:36:16 AM12/18/09
to iphone...@googlegroups.com
ltlfrari wrote:
> I thought I had replied to this but it seems to have gotten lost.
>
It was delayed in moderation, sorry. I just made sure that your posts
will no longer require moderation (which happens automatically after a
certain number of posts)

-- Sean

Reply all
Reply to author
Forward
0 new messages