简体   繁体   中英

Is there a limit on the size of the string passed to jQuery.append()

I wrote a basic program in Angular that uses the router functionality to present two pages as a single page application. So far, that is all it does. I have a page that contains two buttons for navigation, and a wrapper div (ng-view) that is filled with the content of the two pages when the respective button is clicked.

When I try to load the larger of the two pages, I get the following error:

SyntaxError: Unexpected token <

This error is thrown from angular.js:11594 (I am using version 1.3.9). After debugging, I found that an exception is thrown in jQuery, from the code:

this.empty().append( value );

I looked at the input parameter 'value', and it is very large. It contains more than 11,000 lines, and is 1.59 MB large.

I ran the input string in an html format checker ( http://www.freeformatter.com/ ). The format is fine and there is no extra opening tag.

Is it possible that jQuery's method cannot handle such a large string? I searched Google for such a limitation, but all I could find was suggestions for applying limitations using jQuery, and the documentation ( http://devdocs.io/jquery/append ) did not mention such a limit.

Notes:

  1. I am using jQuery version 1.11.0
  2. I cannot update the version, because my team uses PrimeFaces, and this is the version of jQuery that matches the version of PrimeFaces.
  3. The exception is thrown from line 5830.
  4. The large file is created by JSF on the server side. I cannot change it.
  5. I tried using iframes and it works. My guess is that only an iframe element is appended using jQuery, and then the large content is loaded into the iframe. My team leader does not want me to use iframes, so this doesn't help.

Thanks.

First limit you will face is that if the string's over 512 bytes then the dom fragments created by it aren't cached. Next limit is the limit of .innerHTML in the browser is. But it is pretty huge (high)... But while appending lots of content you will face huge lags (It will take very long time to load propably).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM