Fast clearing content

0 views
Skip to first unread message

Cezary

unread,
Apr 30, 2009, 4:41:57 AM4/30/09
to DOMAssistant
Hello,

Before adding content to the container can be cleaned of its contents.
The DA is replaceContent function. With curiosity piece:

DOMAssistant.clearHandlers.apply(this);
this.innerHTML = "";
return DOMAssistant.Content.addContent.call(this, content);

replaced Excerpt:

var e = this.cloneNode(false);
this.parentNode.replaceChild(e, this);
return DOMAssistant.Content.addContent.call(e, content);

and came to me that innerHTML is not always faster. Particularly in
Firefox. After making changes, cleaning works much faster in Firefox
and in some cases in IE. In Safari and Opera and the innerHTML method,
which described the act as quickly.

What do you think?

--
Regards,
Cezary

chenghong

unread,
Apr 30, 2009, 11:59:08 AM4/30/09
to DOMAssistant
Hi there,

Good suggestion. I agree that performance could generally be faster in
your method. However, I'm also concerned about cloneNode not being
able to copy over event handlers or modified / custom attributes. I
have some scenarios in mind and I'll test them out before getting back
to you.

Thanks!

Cheers,
chenghong

Cezary

unread,
Apr 30, 2009, 5:43:14 PM4/30/09
to DOMAssistant
On 30 Kwi, 17:59, chenghong <chengh...@gmail.com> wrote:
> Hi there,
>
> Good suggestion. I agree that performance could generally be faster in
> your method. However, I'm also concerned about cloneNode not being
> able to copy over event handlers or modified / custom attributes. I
> have some scenarios in mind and I'll test them out before getting back
> to you.

Check results. I find the method is quite fast.

One more thing. Do not add the amount of code that solve the problem
with the cache in IE, when it comes to AJAX type GET queries? For
example:

if (method === "GET") {
XMLHttp.setRequestHeader("Cache-Control", "no-cache");
XMLHttp.setRequestHeader("If-Modified-Since", "Wed, 31 Dec
1980 00:00:00 GMT");
XMLHttp.setRequestHeader("Expires", "Wed, 31 Dec 1980
00:00:00 GMT");
}

Just before:

if (method === "POST") {
[...]

Maybe someone will suggest something.

> Thanks!

You welcome!

> Cheers,
> chenghong

--
Regards,
Cezary

chenghong

unread,
May 7, 2009, 9:52:38 AM5/7/09
to DOMAssistant
Hi,

The content clearing method you suggested is fast, but events binded
to the element would be lost. The hassles of reattaching events seem
to wipe off the benefits of cloneNode. I'm open to suggestions though.

As for your second suggestion, perhaps an easier way is to append a
timestamp to the GET query string?


Cheers,
chenghong

Cezary

unread,
May 13, 2009, 12:40:56 PM5/13/09
to DOMAssistant
On 7 Maj, 15:52, chenghong <chengh...@gmail.com> wrote:
> Hi,

Hi,

> The content clearing method you suggested is fast, but events binded
> to the element would be lost. The hassles of reattaching events seem
> to wipe off the benefits of cloneNode. I'm open to suggestions though.

I wonder, since the contents of the container clean, after which the
events are still needed?

> As for your second suggestion, perhaps an easier way is to append a
> timestamp to the GET query string?

Is easier? I do not know. Most importantly, the effect is the same.

--
Regards,
Cezary

chenghong

unread,
May 15, 2009, 6:30:19 AM5/15/09
to DOMAssistant
> I wonder, since the contents of the container clean, after which the
> events are still needed?

Yes, events should still be intact. You want to clear the contents of
an element, not the element itself.

chenghong

Cezary

unread,
May 15, 2009, 7:53:35 AM5/15/09
to DOMAssistant
On 15 Maj, 12:30, chenghong <chengh...@gmail.com> wrote:
> > I wonder, since the contents of the container clean, after which the
> > events are still needed?
>
> Yes, events should still be intact. You want to clear the contents of
> an element, not the element itself.

But the element is made up not only text, but also tags. So remove all
of the container, together with the events added into the elements,
because they are no longer needed.

On the other hand, the DA would be good to see function to swap two
classes.

--
Regards,
Cezary

chenghong

unread,
May 15, 2009, 10:59:23 AM5/15/09
to DOMAssistant
You mean toggling a class on/off, or replacing a class with another?

If it's the later, replaceClass(classA, classB) is currently
available.

I have also thought of adding a toggleClass method.


Cheers,
chenghong

Cezary

unread,
May 18, 2009, 3:22:45 AM5/18/09
to DOMAssistant
On 15 Maj, 16:59, chenghong <chengh...@gmail.com> wrote:
> You mean toggling a class on/off, or replacing a class with another?
>
> If it's the later, replaceClass(classA, classB) is currently
> available.
>
> I have also thought of adding a toggleClass method.

I thought the conversion of one class to another. Yes, toggleClass
would be very usefull.
Reply all
Reply to author
Forward
0 new messages