views:

36

answers:

1

I have a large javascript string. var s = '...............'; // this is about 32000 characters long.

if you wonder: that bit of javascript is autogenerated.

Does anybody know if it is better to store it outside of the javascript For instance in a dom object in the html page and then retrieve it (e.g. var s = document.getElementById('hiddenTextArea').value; ) or is it okay to leave it in the javascript ?

note: I am not interested in the cost occurred in downloading the large string. The question is really if it is okay to store a large string inside the javascript or not and whether there are better ways

Many Thanks

+1  A: 

Storing it in the javascript itself will should always be more performant as you won't have to go through the DOM to retrieve the value.

Justin Niessner
I agree that 'should be more performant' but 'will it be ?' do you know for sure ? There is a big gotcha here and that is that my string is incredibly large.
henryc
It definately will be more performant. Storing in DOM just adds overhead, when you fetch it from the it still has to be stored internally somehow.
Tatu Ulmanen
PERFORMANT is not a word.
Diodeus
it is a word if we use it and we understand what we mean by it.
henryc