I was mess­ing around with a project that pulled in my Gra­vatar tonight. The project had the pos­si­bil­ity of offline access, and I only wanted the page to poll for the image from Gravatar’s site if the user was online. I used the handy navigator.online call, and was able to load just what I needed, only when the user is con­nected to a network:

Javascript

// this self invoking function will check if we are online, and load some goodies if we are
(function offLizzle() {
	// store our element in a var
	var grav = document.getElementById('grav');
	// if we are online, load the gravatar, if not set display to none, as we won't use this element
	if (navigator.onLine) {
		grav.innerHTML = '<img class="pic" src="http://www.gravatar.com/avatar/c8feb28847d8f335a05a233cbd490536.png" alt="Photo of Rob Stinogle" width="40" height="40" />';
	} else {
		grav.style.display = 'none';
	}
})();