innerHTML size limit
I want to use AJAX to load an htmlfile into a <div>
I will then need to run jsMath on this. Everything I have done so far with innerHTML has been a paragraph or two, maybe a table and/or image. Nothing too fancy.
What potential problems may occur when I set innerHTML to an external 25k file, with all sorts of complex css formatting? (thanks to jsMath) I can't think of any other method of doing this, but need to know if there are any limitations.
Thanks in advance.
--Dave
javascript ajax innerhtml
add a comment |
I want to use AJAX to load an htmlfile into a <div>
I will then need to run jsMath on this. Everything I have done so far with innerHTML has been a paragraph or two, maybe a table and/or image. Nothing too fancy.
What potential problems may occur when I set innerHTML to an external 25k file, with all sorts of complex css formatting? (thanks to jsMath) I can't think of any other method of doing this, but need to know if there are any limitations.
Thanks in advance.
--Dave
javascript ajax innerhtml
1
Just a reminder, you should accept answers to your questions. It's the SO way.
– Justin Johnson
Jan 13 '10 at 2:36
add a comment |
I want to use AJAX to load an htmlfile into a <div>
I will then need to run jsMath on this. Everything I have done so far with innerHTML has been a paragraph or two, maybe a table and/or image. Nothing too fancy.
What potential problems may occur when I set innerHTML to an external 25k file, with all sorts of complex css formatting? (thanks to jsMath) I can't think of any other method of doing this, but need to know if there are any limitations.
Thanks in advance.
--Dave
javascript ajax innerhtml
I want to use AJAX to load an htmlfile into a <div>
I will then need to run jsMath on this. Everything I have done so far with innerHTML has been a paragraph or two, maybe a table and/or image. Nothing too fancy.
What potential problems may occur when I set innerHTML to an external 25k file, with all sorts of complex css formatting? (thanks to jsMath) I can't think of any other method of doing this, but need to know if there are any limitations.
Thanks in advance.
--Dave
javascript ajax innerhtml
javascript ajax innerhtml
asked Dec 24 '09 at 1:00
the Hampsterthe Hampster
6061119
6061119
1
Just a reminder, you should accept answers to your questions. It's the SO way.
– Justin Johnson
Jan 13 '10 at 2:36
add a comment |
1
Just a reminder, you should accept answers to your questions. It's the SO way.
– Justin Johnson
Jan 13 '10 at 2:36
1
1
Just a reminder, you should accept answers to your questions. It's the SO way.
– Justin Johnson
Jan 13 '10 at 2:36
Just a reminder, you should accept answers to your questions. It's the SO way.
– Justin Johnson
Jan 13 '10 at 2:36
add a comment |
6 Answers
6
active
oldest
votes
I don't know about any browser specific size limits, but if you assign a string longer that 65536, Chrome splits it into many elem.childNodes
, so you might have to loop over these nodes and concatenate them.
Run the below snipped in Chrome Dev Tools. It constructs a 160 k string, but theDivElement.childNodes[0]
gets clipped to 65536 chars.
var longString = '1234567890';
for (var i = 0; i < 14; ++i) {
longString = longString + longString;
}
console.log('The length of our long string: ' + longString.length);
var elem = document.createElement('div');
elem.innerHTML = longString;
var innerHtmlValue = elem.childNodes[0].nodeValue;
console.log('The length as innerHTML-childNodes[0]: ' + innerHtmlValue.length);
console.log('Num child nodes: ' + elem.childNodes.length);
Result: (Chrome version 39.0.2171.95 (64-bit), Linux Mint 17)
The length of our long string: 163840
The length as innerHTML-childNodes[0]: 65536
Num child nodes: 3
But in Firefox innerHTML
doesn't split the contents into many nodes: (FF version 34.0, Linux Mint 17)
"The length of our long string: 163840"
"The length as innerHTML-childNodes[0]: 163840"
"Num child nodes: 1"
So you'd need to take into account that different browsers handle childNodes
differently, and perhaps iterate over all child nodes and concatenate. (I noticed this, because I tried to use innerHTML
to unescape a > 100k HTML encoded string.)
In fact, in Firefox I can create an innerHTML-childNodes[0]
of length 167 772 160, by looping to i < 24
above. But somewhere above this lenght, there is an InternalError: allocation size overflow
error.
Instead of iterating over all child nodes, we can call node.normalize() method.
– Kevin Yue
Dec 27 '18 at 5:43
add a comment |
There's nothing to prevent you from doing this technically. The biggest issue will be page load time. Be sure to include some sort of indication that the data is loading or it will look like nothing's happening.
add a comment |
In the application I am currently working on, I have not had any problems in any browser setting innerHTML to a string of 30k or more. (Don't know what the limit is)
add a comment |
The only kind of limits that are on this type of thing are purely bandwidth and processor related. You should make sure you don't have a low timeout set on your ajax request. You should also test on some lower speed computers to see if there is a memory issue. Some old browsers can be pretty unforgiving of large objects in memory.
add a comment |
You'll probably want to profile this with a tool like dynatrace ajax or speed tracer to understand how setting innerHTML to a really huge value affects performance. You might want to compare it with another approach like putting the new content in an iframe, or paginating the content.
I hadn't thought of that <i>per se</i> I'm using AJAX to decide between Chapter 6 review, Chapter 7 review etc, but I hadn't thought to split each review up. Thanks
– the Hampster
Dec 24 '09 at 4:41
add a comment |
your limit will be most likely the download limit set from your web server. usually a couple of MBs.Several web frameworks allows increasing this size but you cant just do that because that would mean increase buffer size which is not a good thing.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f1956170%2finnerhtml-size-limit%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
I don't know about any browser specific size limits, but if you assign a string longer that 65536, Chrome splits it into many elem.childNodes
, so you might have to loop over these nodes and concatenate them.
Run the below snipped in Chrome Dev Tools. It constructs a 160 k string, but theDivElement.childNodes[0]
gets clipped to 65536 chars.
var longString = '1234567890';
for (var i = 0; i < 14; ++i) {
longString = longString + longString;
}
console.log('The length of our long string: ' + longString.length);
var elem = document.createElement('div');
elem.innerHTML = longString;
var innerHtmlValue = elem.childNodes[0].nodeValue;
console.log('The length as innerHTML-childNodes[0]: ' + innerHtmlValue.length);
console.log('Num child nodes: ' + elem.childNodes.length);
Result: (Chrome version 39.0.2171.95 (64-bit), Linux Mint 17)
The length of our long string: 163840
The length as innerHTML-childNodes[0]: 65536
Num child nodes: 3
But in Firefox innerHTML
doesn't split the contents into many nodes: (FF version 34.0, Linux Mint 17)
"The length of our long string: 163840"
"The length as innerHTML-childNodes[0]: 163840"
"Num child nodes: 1"
So you'd need to take into account that different browsers handle childNodes
differently, and perhaps iterate over all child nodes and concatenate. (I noticed this, because I tried to use innerHTML
to unescape a > 100k HTML encoded string.)
In fact, in Firefox I can create an innerHTML-childNodes[0]
of length 167 772 160, by looping to i < 24
above. But somewhere above this lenght, there is an InternalError: allocation size overflow
error.
Instead of iterating over all child nodes, we can call node.normalize() method.
– Kevin Yue
Dec 27 '18 at 5:43
add a comment |
I don't know about any browser specific size limits, but if you assign a string longer that 65536, Chrome splits it into many elem.childNodes
, so you might have to loop over these nodes and concatenate them.
Run the below snipped in Chrome Dev Tools. It constructs a 160 k string, but theDivElement.childNodes[0]
gets clipped to 65536 chars.
var longString = '1234567890';
for (var i = 0; i < 14; ++i) {
longString = longString + longString;
}
console.log('The length of our long string: ' + longString.length);
var elem = document.createElement('div');
elem.innerHTML = longString;
var innerHtmlValue = elem.childNodes[0].nodeValue;
console.log('The length as innerHTML-childNodes[0]: ' + innerHtmlValue.length);
console.log('Num child nodes: ' + elem.childNodes.length);
Result: (Chrome version 39.0.2171.95 (64-bit), Linux Mint 17)
The length of our long string: 163840
The length as innerHTML-childNodes[0]: 65536
Num child nodes: 3
But in Firefox innerHTML
doesn't split the contents into many nodes: (FF version 34.0, Linux Mint 17)
"The length of our long string: 163840"
"The length as innerHTML-childNodes[0]: 163840"
"Num child nodes: 1"
So you'd need to take into account that different browsers handle childNodes
differently, and perhaps iterate over all child nodes and concatenate. (I noticed this, because I tried to use innerHTML
to unescape a > 100k HTML encoded string.)
In fact, in Firefox I can create an innerHTML-childNodes[0]
of length 167 772 160, by looping to i < 24
above. But somewhere above this lenght, there is an InternalError: allocation size overflow
error.
Instead of iterating over all child nodes, we can call node.normalize() method.
– Kevin Yue
Dec 27 '18 at 5:43
add a comment |
I don't know about any browser specific size limits, but if you assign a string longer that 65536, Chrome splits it into many elem.childNodes
, so you might have to loop over these nodes and concatenate them.
Run the below snipped in Chrome Dev Tools. It constructs a 160 k string, but theDivElement.childNodes[0]
gets clipped to 65536 chars.
var longString = '1234567890';
for (var i = 0; i < 14; ++i) {
longString = longString + longString;
}
console.log('The length of our long string: ' + longString.length);
var elem = document.createElement('div');
elem.innerHTML = longString;
var innerHtmlValue = elem.childNodes[0].nodeValue;
console.log('The length as innerHTML-childNodes[0]: ' + innerHtmlValue.length);
console.log('Num child nodes: ' + elem.childNodes.length);
Result: (Chrome version 39.0.2171.95 (64-bit), Linux Mint 17)
The length of our long string: 163840
The length as innerHTML-childNodes[0]: 65536
Num child nodes: 3
But in Firefox innerHTML
doesn't split the contents into many nodes: (FF version 34.0, Linux Mint 17)
"The length of our long string: 163840"
"The length as innerHTML-childNodes[0]: 163840"
"Num child nodes: 1"
So you'd need to take into account that different browsers handle childNodes
differently, and perhaps iterate over all child nodes and concatenate. (I noticed this, because I tried to use innerHTML
to unescape a > 100k HTML encoded string.)
In fact, in Firefox I can create an innerHTML-childNodes[0]
of length 167 772 160, by looping to i < 24
above. But somewhere above this lenght, there is an InternalError: allocation size overflow
error.
I don't know about any browser specific size limits, but if you assign a string longer that 65536, Chrome splits it into many elem.childNodes
, so you might have to loop over these nodes and concatenate them.
Run the below snipped in Chrome Dev Tools. It constructs a 160 k string, but theDivElement.childNodes[0]
gets clipped to 65536 chars.
var longString = '1234567890';
for (var i = 0; i < 14; ++i) {
longString = longString + longString;
}
console.log('The length of our long string: ' + longString.length);
var elem = document.createElement('div');
elem.innerHTML = longString;
var innerHtmlValue = elem.childNodes[0].nodeValue;
console.log('The length as innerHTML-childNodes[0]: ' + innerHtmlValue.length);
console.log('Num child nodes: ' + elem.childNodes.length);
Result: (Chrome version 39.0.2171.95 (64-bit), Linux Mint 17)
The length of our long string: 163840
The length as innerHTML-childNodes[0]: 65536
Num child nodes: 3
But in Firefox innerHTML
doesn't split the contents into many nodes: (FF version 34.0, Linux Mint 17)
"The length of our long string: 163840"
"The length as innerHTML-childNodes[0]: 163840"
"Num child nodes: 1"
So you'd need to take into account that different browsers handle childNodes
differently, and perhaps iterate over all child nodes and concatenate. (I noticed this, because I tried to use innerHTML
to unescape a > 100k HTML encoded string.)
In fact, in Firefox I can create an innerHTML-childNodes[0]
of length 167 772 160, by looping to i < 24
above. But somewhere above this lenght, there is an InternalError: allocation size overflow
error.
edited Dec 18 '14 at 12:06
answered Dec 18 '14 at 11:33
KajMagnusKajMagnus
5,90975596
5,90975596
Instead of iterating over all child nodes, we can call node.normalize() method.
– Kevin Yue
Dec 27 '18 at 5:43
add a comment |
Instead of iterating over all child nodes, we can call node.normalize() method.
– Kevin Yue
Dec 27 '18 at 5:43
Instead of iterating over all child nodes, we can call node.normalize() method.
– Kevin Yue
Dec 27 '18 at 5:43
Instead of iterating over all child nodes, we can call node.normalize() method.
– Kevin Yue
Dec 27 '18 at 5:43
add a comment |
There's nothing to prevent you from doing this technically. The biggest issue will be page load time. Be sure to include some sort of indication that the data is loading or it will look like nothing's happening.
add a comment |
There's nothing to prevent you from doing this technically. The biggest issue will be page load time. Be sure to include some sort of indication that the data is loading or it will look like nothing's happening.
add a comment |
There's nothing to prevent you from doing this technically. The biggest issue will be page load time. Be sure to include some sort of indication that the data is loading or it will look like nothing's happening.
There's nothing to prevent you from doing this technically. The biggest issue will be page load time. Be sure to include some sort of indication that the data is loading or it will look like nothing's happening.
answered Dec 24 '09 at 1:04
Alex ReisnerAlex Reisner
23.7k54951
23.7k54951
add a comment |
add a comment |
In the application I am currently working on, I have not had any problems in any browser setting innerHTML to a string of 30k or more. (Don't know what the limit is)
add a comment |
In the application I am currently working on, I have not had any problems in any browser setting innerHTML to a string of 30k or more. (Don't know what the limit is)
add a comment |
In the application I am currently working on, I have not had any problems in any browser setting innerHTML to a string of 30k or more. (Don't know what the limit is)
In the application I am currently working on, I have not had any problems in any browser setting innerHTML to a string of 30k or more. (Don't know what the limit is)
answered Dec 24 '09 at 1:05
Roland BoumanRoland Bouman
24.6k55360
24.6k55360
add a comment |
add a comment |
The only kind of limits that are on this type of thing are purely bandwidth and processor related. You should make sure you don't have a low timeout set on your ajax request. You should also test on some lower speed computers to see if there is a memory issue. Some old browsers can be pretty unforgiving of large objects in memory.
add a comment |
The only kind of limits that are on this type of thing are purely bandwidth and processor related. You should make sure you don't have a low timeout set on your ajax request. You should also test on some lower speed computers to see if there is a memory issue. Some old browsers can be pretty unforgiving of large objects in memory.
add a comment |
The only kind of limits that are on this type of thing are purely bandwidth and processor related. You should make sure you don't have a low timeout set on your ajax request. You should also test on some lower speed computers to see if there is a memory issue. Some old browsers can be pretty unforgiving of large objects in memory.
The only kind of limits that are on this type of thing are purely bandwidth and processor related. You should make sure you don't have a low timeout set on your ajax request. You should also test on some lower speed computers to see if there is a memory issue. Some old browsers can be pretty unforgiving of large objects in memory.
answered Dec 24 '09 at 1:06
Alex SextonAlex Sexton
9,76812339
9,76812339
add a comment |
add a comment |
You'll probably want to profile this with a tool like dynatrace ajax or speed tracer to understand how setting innerHTML to a really huge value affects performance. You might want to compare it with another approach like putting the new content in an iframe, or paginating the content.
I hadn't thought of that <i>per se</i> I'm using AJAX to decide between Chapter 6 review, Chapter 7 review etc, but I hadn't thought to split each review up. Thanks
– the Hampster
Dec 24 '09 at 4:41
add a comment |
You'll probably want to profile this with a tool like dynatrace ajax or speed tracer to understand how setting innerHTML to a really huge value affects performance. You might want to compare it with another approach like putting the new content in an iframe, or paginating the content.
I hadn't thought of that <i>per se</i> I'm using AJAX to decide between Chapter 6 review, Chapter 7 review etc, but I hadn't thought to split each review up. Thanks
– the Hampster
Dec 24 '09 at 4:41
add a comment |
You'll probably want to profile this with a tool like dynatrace ajax or speed tracer to understand how setting innerHTML to a really huge value affects performance. You might want to compare it with another approach like putting the new content in an iframe, or paginating the content.
You'll probably want to profile this with a tool like dynatrace ajax or speed tracer to understand how setting innerHTML to a really huge value affects performance. You might want to compare it with another approach like putting the new content in an iframe, or paginating the content.
answered Dec 24 '09 at 1:13
AnnieAnnie
6,4311827
6,4311827
I hadn't thought of that <i>per se</i> I'm using AJAX to decide between Chapter 6 review, Chapter 7 review etc, but I hadn't thought to split each review up. Thanks
– the Hampster
Dec 24 '09 at 4:41
add a comment |
I hadn't thought of that <i>per se</i> I'm using AJAX to decide between Chapter 6 review, Chapter 7 review etc, but I hadn't thought to split each review up. Thanks
– the Hampster
Dec 24 '09 at 4:41
I hadn't thought of that <i>per se</i> I'm using AJAX to decide between Chapter 6 review, Chapter 7 review etc, but I hadn't thought to split each review up. Thanks
– the Hampster
Dec 24 '09 at 4:41
I hadn't thought of that <i>per se</i> I'm using AJAX to decide between Chapter 6 review, Chapter 7 review etc, but I hadn't thought to split each review up. Thanks
– the Hampster
Dec 24 '09 at 4:41
add a comment |
your limit will be most likely the download limit set from your web server. usually a couple of MBs.Several web frameworks allows increasing this size but you cant just do that because that would mean increase buffer size which is not a good thing.
add a comment |
your limit will be most likely the download limit set from your web server. usually a couple of MBs.Several web frameworks allows increasing this size but you cant just do that because that would mean increase buffer size which is not a good thing.
add a comment |
your limit will be most likely the download limit set from your web server. usually a couple of MBs.Several web frameworks allows increasing this size but you cant just do that because that would mean increase buffer size which is not a good thing.
your limit will be most likely the download limit set from your web server. usually a couple of MBs.Several web frameworks allows increasing this size but you cant just do that because that would mean increase buffer size which is not a good thing.
answered Dec 24 '09 at 1:40
Eugene RamirezEugene Ramirez
1,56621515
1,56621515
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f1956170%2finnerhtml-size-limit%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Just a reminder, you should accept answers to your questions. It's the SO way.
– Justin Johnson
Jan 13 '10 at 2:36