Rama Rao M
Rama Rao M

Reputation: 3051

What is maximum limit of data can be set through jQuery html() method

I am changing the div content through jQuery .html() method once I get the response text from Ajax event.

Sometimes I get more response data (contains html and script and about to 4MB data). It does take more time to set the response data as div content using jQuery .html() method.

Can somebody tell me the reason? Are there any solution or alternatives?

Upvotes: 4

Views: 2148

Answers (1)

jfriend00
jfriend00

Reputation: 707716

First off, regularly downloading and inserting 4MB of HTML is NEVER going to make for a fast, interactive application. It's going to be a network hog and a memory hog and not perform well.

There is no technical limit to the .html() method other than how much memory the browser can get access to. .html() is a shell on top of the native .innerHTML property which has no particular limits.

4MB of HTML takes a significant time to download and a significant time for the browser to parse. That's probably the delay you see. The time is probably not related to jQuery. After a little initial housekeeping which has nothing to do with the actual content you are setting, jQuery just sets the .innerHTML property and the browser handles parsing the HTML content you gave it.

Now, if you are replacing a large amount of HTML (e.g. another 4MB set of HTML), then jQuery might be a lot slower because it has to traverse every element in the old content and make sure it has cleaned up any jQuery state associated with those elements that are about to be removed.


You really ought to fix your page design/app design so that you don't have to use 4MB of HTML.

Upvotes: 3

Related Questions