Question

I am working on a jQuery plugin that people can include in their own page. The plugin spawns jobs at a service I am operating which is on a different domain.

To breach the domain boundary I am using jQuery's JSONP functionality which works fine for spawning the job. However, I also need to display the "progress" (0 -> 100%). So far my plan was to continuously "poll" for the progress of the job (comet would be nicer, but AFAIK is not possible cross-domain).

The problem is that polling for the progress every second causes Firefox to constantly flash "Loading ..." within the tab's title which I find seriously annoying. (Firefox does that because JSONP works through script tags being attached to the DOM which it then "loads").

So the meat of my question is:

Is it possible to surpress the "Loading ..." tab title messages - or - is there a better way to "stream" the progress updates in a cross-domain fashion?

-- Felix Geisendörfer

Was it helpful?

Solution

If it's a long running job, maybe you can get some average run times and fake it for the user, using infrequent polling to adjust your faked percent complete.

Say an average job takes ten minutes. You can figure what percent should be done each second on average, and fake update that amount entirely on the client side.

Then when your thirty second timer runs out, poll the server to get the actual percent complete, and update the rate of your progress bar so the fake on the client side will finish at the new estimated finish time of the server job.

You can do some math to find a middle ground between your average performance and the time you're currently measuring, but that depends on the variability of the time to run the job.

OTHER TIPS

Unfortunately, the ajax call will only return once it has completed, so there is no way to have it update you on its progress.

I would recommend using a loading spinner or something.

If it's an absolute requirement to show precise loading progress, you may need to approach it from a different angle.

CORS support is getting pretty widespread these days. You could now solve the problem properly by using CORS to OK cross-domain XMLHttpRequests and it's trivial to detect a lack of CORS support and fall back to JSONP for older browsers.

There's example detection code on that first link, in-depth details on how it works on MDC, and, if you want details on browser compatibility, I updated the Wikipedia article a few days ago.

The gist of it is:

  • Any modern WebKit browser (Safari 4+, Chrome 3+, new Flock, etc.)
  • Anything Gecko 1.9.1+ (Firefox 3.5+, SeaMonkey 2.0+, etc.)
  • Internet Explorer 8+ and anything based on it (Sleipnir, etc.) ...with the caveat that it doesn't implement the flag to pass credentials and cookies with the request.

The notable exceptions are:

  • Opera (no support as of 10.61)
  • Camino (2.0.5 is based on Gecko 1.9.0 (Firefox 3.0))
  • Arora (As of Arora 0.10.2, it has the API, but a bug causes requests to fail)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top