Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handler for offline mode #20

Open
anzorb opened this issue Feb 12, 2013 · 5 comments
Open

Add handler for offline mode #20

anzorb opened this issue Feb 12, 2013 · 5 comments

Comments

@anzorb
Copy link

anzorb commented Feb 12, 2013

Hello, great plugins, although I'm having issues when my Google Feeds HTML5 Application is in offline mode. Here's the error I get:
GET http://www.google.com/jsapi?callback=__mm_asynch_req__1360698411216 Network unavailable

As in any other offline news reader, I want to ignore the API if there's no connection.
I've tried adding if statements to either goog.js or async.js (if(!navigator.onLine) return), but to no luck - I find that my application cannot initialize because of the following error:

Error: Load timeout for modules: goog!feeds_unnormalized2,goog!feeds

What's the quickest way to check if internet connection is available, and if not, continue application initialization?

Thanks,
A.

@orientalperil
Copy link

@anzorb Did you find any solution to your problem? I'm having the same issue. I want to be able to run my unit tests offline, but this seems not doable if the async plugin is used.

@oniric85
Copy link

I'm also interested to this. I need to have some sort of fallback on a mobile device if network is turned off.

@tysonnero
Copy link

I'm using the async plugin and can degrade gracefully when using Google Maps in offline mode. All you have to do is implement the standard RequireJS error handling such as this http://requirejs.org/docs/api.html#errbacks.

@ghost
Copy link

ghost commented Sep 23, 2013

tysonnero, can you provide an example of how you are accomplishing this? Thanks!

@tysonnero
Copy link

Firstly, I implemented something close to what Joe Zim did here for lazy loading with RequireJS:
http://www.joezimjs.com/javascript/lazy-loading-javascript-with-requirejs/

I'm using AngularJs, so the implementation is a little different. The important thing to note is that the lazy-loader (which I've named ModuleLoader) takes advantage of RequireJS's error callbacks. If the script doesn't load, it will fall into the error condition.

Next, rather than referencing the async plugin within the module dependency array, I use the ModuleLoader to attempt to load the script in the function definition. If the script doesn't load, I gracefully handle the error.

var loader = new ModuleLoader();
loader.get('async!http://maps.google.com/maps/api/js?v=3&sensor=false').then(function () {
  initialize();
}, function (err) {
     handleError(err);
});

Lastly, I've recently been looking at ways to detect being offline prior to loading the script. This seems to be the best way to handle things as I've noticed there are further issues with RequireJS such as caching the failed load.

Take a look the the window.navigator.onLine property as well as other options as trying to ping an online service.

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

No branches or pull requests

4 participants