Bug Tracker

Ticket #7898 (closed enhancement: invalid)

Opened 4 years ago

Last modified 3 years ago

replaceWith() terribly slow in IE8

Reported by: info@… Owned by:
Priority: undecided Milestone:
Component: manipulation Version: 1.4.4
Keywords: Cc:
Blocking: Blocked by:

Description

When using $('elm').replaceWith(string) where elm has multiple nested children (need not be a lot) it took IE8 10 seconds to perform its task.

After having modified the replaceWith() method in the jQuery source:

  • jQuery( this ).remove();

+ jQuery( this ).empty().remove();

It took IE8 less than a second to complete its task, like in Firefox 3.6

Change History

comment:1 Changed 4 years ago by jitter

  • Status changed from new to closed
  • Resolution set to invalid
  • Component changed from unfiled to manipulation
  • Milestone 1.6 deleted

Thanks for taking the time to contribute to the jQuery project by writing a bug report. The reason for this is that replaceWith() returns the removed element. The documentation says

[...] the original jQuery object is returned. This object refers to the element that has been removed from the DOM, not the new element that has replaced it.`

If you don't need this "return" value you can just yourself call $('elem').empty().replaceWith(string) instead of modifying the jQuery source which is a very bad idea (consider the hassle when upgrading to another jQuery version, breaking replaceWith for e.g. plugins relying on the specified behavior)

I made a "hacked up"  test case which shows how incorporating your "fix" breaks the behavior of replaceWith().

comment:2 Changed 4 years ago by info@…

Thanks for your quick and appopriate response! Good suggestion.

comment:3 Changed 3 years ago by Anton Vodonsov

I am also having problems with <code>relpaceWith</code> performance; but in my case <code>.emtpy()</code> doesn't help.

I am using DOM API, <code>replaceChild</code>, it works about 5 times faster.

I test this by replacing HTML table; IE8; jquery 1.6.1.

Crossposting this info here from the discussion at  https://issues.apache.org/jira/browse/WICKET-4236.

Note: See TracTickets for help on using tickets.