I need to store relatively larget bit of JSON for global access in my web app.
Should I use jquery's $.data(document.body, 'some-reference-here', MyJsonObj);
or a global?
I know binding $.data() to document.body is faster than to a jquery o开发者_如何学Pythonbject, but how does this compare to global variable?
I'm interested the most efficient memory usage.
Global variable in browser JS means window.variable
, so I think it would be much faster then
$.data(document.body, 'some-reference-here', MyJsonObj);
just because this is only one touch of the object's property instead of function call, getting property of document and much staff inside of the data call. But another problem is polluting global scope. Maybe it's better to store this data somewhere inside the local scope of your script.
精彩评论