[WEBDIALOG] getJSON from source folder
-
Hi.
(this topic is related to NODE-GUI development BTW..)
Been fiddeling with Jquery getJSON a little and have some quiries.
I have quite a large configuration data that needs to be hardcoded.
Basically info concering each node that cannot be created
dynamically.Normally I suppose I could just store it into a simple JS object, but during a session
it is not likely all nodes from that library would get used. There could be hundreds+!
So it seams like waste of energy for the browser caching all that..So I tried to store a config.json in the source folder and use
Jquery.getJSON() and it seams to be working fine. Something like:$.ajaxSetup({ cache;false });//prevent from caching the whole file $.getJSON("JSON/myjson.json", function(data){ // traverse data here and store in variable or whatever.. }
Now off course I'm wondering if this is a safe way off doing things or could run
into browser specific trouble or security_policy breaches. I don't think I'm violating
the same origin policy?
Been googeling the subject quite hard but doing this is in Sketchup and it's enviroment
is so specific it's quite hard to relate.Maybe I'm overcomplicating this. Just store that damn thing in a object
NOTE: I'm only Reading the JSON, not storing any data.
Also I have considered the issue of error check for valid JSON. -
For local files it behaves sometimes different. (I also ran into similar issues, and got it working but now it isn't working anymore. I'll look it up and post back.)
Since JSON is also JavaScript, are there any reasons why you couldn't load it as .js file? Create a<script>
element withscr="JSON/myjson.js"
and attach it todocument
. -
Hi Aerilius!
@unknownuser said:
during a session
it is not likely all nodes from that library would get used. There could be hundreds+!
So it seams like waste of energy for the browser caching all that..Like I said, there is no problem having it in a separate JS or even in the main js file.
I just thought I could get better performance that way, by not loading in the static configuration data unless requested for.
If keeping it in the js there would be no need to use JSON though..There will be many Icons and SVG curve rendering so it all will add up. At the moment the GUI is not swamped with stuff so I can't really see the performance hit as it will get. Maybe I'm just over complicating the matter..
As usual the big bottleneck will probably be in SU somewhere..@unknownuser said:
For local files it behaves sometimes different. (I also ran into similar issues, and got it working but now it isn't working anymore. I'll look it up and post back.)
Ahh. OK.. It's working for me though right now. Are you also writing?
I'm just interrested in reading files.If there are any issues I'll just dump the idea, no biggies..
Thanks for the help, appreciate it!
edit: Btw might mention that I'm creating this JSON file myself, so there isen't a dependancy for a framwork or anything like that..
Looking forward to your ideas on the matter, AE
-
I meant "create the script element dynamically" (only on demand). Not sure if you understood it like thatβ¦
-
No. I did not understand it like that, and I still don't not know what you mean by "loading script element dynamically" and scr="JSON/myjson.js".
That would cache the whole file loading it in the first time anyway, no?
I'm sure your thinking of something more cleverly then I, so exuze me if I sound off.
I don't consider this being a problem, more of an interesting solution if I can have it working properly..
edit: you mean with "document.write". That's seams to be sketchy.?
-
I'm setting this aside for the moment. Getting errors in crome debugger.
"Origin null is not allowed by Access-Control-Allow-Origin."
Crome has reputation being very hard on applying the "Same Origin Policy" to local files.
But this still indicates that it could cause trouble for me later on..
-
For ajax calls you need to use JSONP to avoid XSS blocking.
-
JSONPadding Will try that.
Thanks a lot!
Advertisement