Skip to content
This repository has been archived by the owner on Jan 26, 2020. It is now read-only.

Sugestion for improvement: static load of JSON data #67

Closed
minixxie opened this issue Feb 26, 2013 · 10 comments
Closed

Sugestion for improvement: static load of JSON data #67

minixxie opened this issue Feb 26, 2013 · 10 comments

Comments

@minixxie
Copy link

Hi,

I'm trying to use this library in my symfony2 project, where I have TWO virtual hosts, host (A) for the website and host (B) for the static contents like js, css, img.

Since I suppose the timezone json data (generated with node-parse.js) is relatively static, I'd like to put it under host (B). However, since the website is on host (A), I found that either in sync/async mode, it failed to load the json data file. After several struggling, I realized that it is a cross-origin request which is by-default not allowed, unless I set some Apache directive to allow the cross-domain visit.

Also, I found that "processData()" is a private function in the library which is the core for assign the JSON data into your timezone object. If this function can be reached by the user, I can include the json content, and then pass the json structure into this function. This saves me a request.

Maybe only I have such a requirement as I'd like to load timezones for all countries beforehand. Pls consider this. Thanks.

Simon

@longlho
Copy link
Collaborator

longlho commented Feb 27, 2013

hmm you can use JSONP if you don't wanna deal w/ CORS stuff. Can you clarify your proposed method a bit?

@minixxie
Copy link
Author

something like:

<script src="all-cities-tz-data.js" />
<script src="timezone-js/date.js" />
<script>
$(document).ready(function(){
    timezoneJS.timezone.parseJsonData( tzData );
});
</script>

where all-cities-tz-data.js is an assignment of the node-parse.js generated data to an variable:

var tzData = {
zones: { .... 
};

As in symfony2, I can "concatenate" the above 2 js files into one, with its "Assetic" bundle, these 2 js files will finally require only ONE requests. And this request can be fetched from another "origin".

I have no experience on JSONP so my suggestion here may not be good enough, this is just for a reference.

Simon

@longlho
Copy link
Collaborator

longlho commented Feb 28, 2013

hmm my suggestion would be what you've already had right now, which is pre-processed static data (minified and gzipped) and send everything down as 1 min.js to avoid extra asset loading requests.

During the pre-process stage you can embed JSON no problem.

@minixxie
Copy link
Author

I see. Thanks for your info. Right now, I couldn't find any "parseJsonData()" like function to call, so I'm using it with an extra "sync" request now. But it has some other errors reported, let me write them in a separate issue.

@longlho
Copy link
Collaborator

longlho commented Feb 28, 2013

hmm have you tried loadZoneDataFromObject?

@minixxie
Copy link
Author

Oh I didn't. Thanks for your reminder. Finally I got it work with:

timezoneJS.timezone.loadingScheme = timezoneJS.timezone.loadingSchemes.MANUAL_LOAD;
timezoneJS.timezone.loadZoneJSONData('/tz/all-tz.json', true);

but if I change the above "true" to "false", I got error:
hms is null

@longlho
Copy link
Collaborator

longlho commented Feb 28, 2013

hmm I'll try to take a look at it. Can u throw in a bug report for it? Did loadZoneDataFromObject work for your use case?

@minixxie
Copy link
Author

I think I'm not going to use loadZoneDataFromObject for now. loadZoneJSONData() now works well for me (with sync=true). Thanks.

@longlho
Copy link
Collaborator

longlho commented Feb 28, 2013

Cool :) Tks

@minixxie
Copy link
Author

Thank you :D
btw, reported the above "hms is null" in #68

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants