Using Dojo in a gadget

Dojo (pre 1.7) has issues working correctly in an open social gadget because of the way code is loaded.

There are 2 ways to load code in an open social gadget:

  1. Script tag injection
  2. XHR requests

In order to make XHR requests in an open social gadget, you must first have a fully built url, and then pass that url to a makeRequest or osapi.http api which will fetch the url through a proxy. Script tag injection does not suffer from the same origin limitations as xhr requests do, and thus do not need to make use of a proxy.

Dojo 1.7+ uses the script injection method of code loading, so it is recommended that gadgets use this version.

Prior versions(before 1.7) of dojo can be made to load code in the same way. Dojo will need to be built to use the cross domain (xdomain) loader. The xdomain loader is not the normal loader, so existing code could potentially have unexpected issues.

In either case, it should be noted that dojo's xhr module will not work well in a gadget environment and some tweaking is required to get it to work transparently. An example of piping dojo's xhr requests through the osapi.http api is shown below.

Examples

  1. Simple dojo 1.4.3 gadget
  2. Simple dojo 1.7 gadget
  3. Simple dojo 1.8 gadget
  4. Dojo 1.8 xhr demo