简体   繁体   English

传递给jQuery.append()的字符串大小是否有限制

[英]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. 我在Angular中编写了一个基本程序,它使用路由器功能将两个页面呈现为单页面应用程序。 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. 我有一个页面,其中包含两个用于导航的按钮,以及一个包装div(ng-view),当单击相应的按钮时,该页面填充了两个页面的内容。

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). 从angular.js:11594抛出此错误(我使用的是版本1.3.9)。 After debugging, I found that an exception is thrown in jQuery, from the code: 调试之后,我发现jQuery中抛出了一个异常,代码如下:

this.empty().append( value );

I looked at the input parameter 'value', and it is very large. 我查看了输入参数'value',它非常大。 It contains more than 11,000 lines, and is 1.59 MB large. 它包含超过11,000行,大1.59 MB。

I ran the input string in an html format checker ( http://www.freeformatter.com/ ). 我在html格式检查器( 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? 是否有可能jQuery的方法无法处理如此大的字符串? 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. 我在Google上搜索了这样的限制,但我发现的只是使用jQuery应用限制的建议,文档( http://devdocs.io/jquery/append )没有提到这样的限制。

Notes: 笔记:

  1. I am using jQuery version 1.11.0 我正在使用jQuery版本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. 我无法更新版本,因为我的团队使用PrimeFaces,这是与PrimeFaces版本匹配的jQuery版本。
  3. The exception is thrown from line 5830. 从5830行抛出异常。
  4. The large file is created by JSF on the server side. 大文件由JSF在服务器端创建。 I cannot change it. 我无法改变它。
  5. I tried using iframes and it works. 我尝试使用iframe,但它确实有效。 My guess is that only an iframe element is appended using jQuery, and then the large content is loaded into the iframe. 我的猜测是只使用jQuery附加iframe元素,然后将大内容加载到iframe中。 My team leader does not want me to use iframes, so this doesn't help. 我的团队负责人不希望我使用iframe,所以这没有帮助。

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. 你要面对的第一个限制是,如果字符串超过512个字节,那么它创建的dom片段不会被缓存。 Next limit is the limit of .innerHTML in the browser is. 下一个限制是浏览器中.innerHTML的限制。 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). 但是它非常巨大(高)......但是在附加大量内容的同时,你将面临巨大的滞后(可能需要很长时间才能加载)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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