Thanks for responding.
I understand when to dynamically load the api and when not to - my
concern is with the callback function when dynamic loading AND
autoloading. Let me be more specific:
I would like to dynamically load the api and with it the feeds api
(via autoloading) .
I believe I can do as follows:
function initLoader() {
var script = document.createElement("script");
script.src = "http://www.google.com/jsapi?autoload%3D%7B%22modules
%22%3A%5B%7B%22name%22%3A%22feeds%22%2C%22version%22%3A%221%22%7D%5D
%7D&key=ABCDEFG";
script.type = "text/javascript";
document.getElementsByTagName("head")[0].appendChild(script);
}
in this case, the autoload parameter is the URL Encoded version of:
{
"modules" : [
{
"name" : "feeds",
"version" : "1.0",
}
]
}
My concern in this case is how to execute the callback function when
dynamically loading jsapi and autoloading the feeds api.
I could set the callback function as a parameter to jsapi as follows:
var script = document.createElement("script");
script.src = "http://www.google.com/jsapi?
callback=myCallBackFunction&autoload%3D%7B%22modules%22%3A%5B%7B%22name
%22%3A%22feeds%22%2C%22version%22%3A%221%22%7D%5D%7D&key=ABCDEFG";
script.type = "text/javascript";
document.getElementsByTagName("head")[0].appendChild(script);
I am worried that in this case that the callback fn will execute when
jsapi code is ready but before the feeds module is fully loaded.
I could also set it inside the feeds module autoload parameter itself,
so that my autoload parameter is the url encoded version of:
{
"modules" : [
{
"name" : "feeds",
"version" : "1.0",
"options": {"callback" : myCallBackFunction}
}
]
}
The API does not seem to get specific enough with respect to
autloading and callbacks.
On May 12, 7:30 pm, Jeremy Geerdes <[email protected]> wrote:
> The support for these features is included in the API for additional
> flexibility. How you implement the API on your site and in your
> application will depend very much on what you're trying to do. If you
> have a page that depends on the Feeds API, you will want to use the
> jsapi by including it via a remote script tag, right in the page. If
> you have a page that doesn't need the API right immediately, or you
> want to load other primary content faster, you can use the jsapi?
> callback= method to load the script asynchronously. The autoload
> params can dramatically clean up your code. And the list goes on and
> on. Usually, when I load the api for a general page, I do it like this:
>
> <script type="text/javascript" src="http://www.google.com/jsapi"></
> script>
> <script type="text/javascript">
> google.load(...); // the apis I want to load
> function init(){
> // what I want to do onload
> }
> google.setOnLoadCallback(init);
> </script>
>
> Jeremy R. Geerdes
> Effective website design & development
> Des Moines, IA
>
> For more information or a project
> quote:http://jgeerdes.home.mchsi.comhttp://jgeerdes.blogspot.comhttp://jgeerdes.wordpress.com
> [email protected]
>
> Unless otherwise noted, any price quotes contained within this
> communication are given in US dollars.
>
> If you're in the Des Moines, IA, area, check out Debra Heights
> Wesleyan Church!
>
> And check out my blog, Adventures in Web Development,
> athttp://jgeerdes.blogspot.com
> !
>
> On May 12, 2009, at 6:20 PM, snowcavalier wrote:
>
>
>
> > Just to clarify:
>
> > By dynamic loading i mean dynamically creating a script to jsapi.
> > By autoloading i mean including the api (in my case the feeds api) as
> > a parameter to jsapi to eliminate an additional load.
>
> > It seems there are two different ways to do the callback.
> > 1) You can specify a callback as its own parameter to jsapi (like
> > "&callback=googleAPILoaded").
> > 2) You can also specify a callback inside the autoloading of the feeds
> > api by url encoding "{"callback" : feedAPILoaded}"
>
> > Is there a best or proper way to do this? Is it certain that the feed
> > api will be loaded in both cases? I'm tempted to use the second.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google AJAX APIs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-AJAX-Search-API?hl=en
-~----------~----~----~----~------~----~------~--~---