English subtitles

← Network status - Mobile Web Development

Get Embed Code
4 Languages

Showing Revision 4 created 05/24/2016 by Udacity Robot.

  1. In fact, this is a really important point. The
  2. browser can't really tell that it's definitively online. It
  3. can't tell that it's definitively offline either, unless it
  4. really has no connection to another device at all.
  5. In fact there's an attribute, navigator.onLine, that supposedly tells
  6. you whether you're online or not. There's also a
  7. pair of events that fire up the body of
  8. the document when you go online or offline. However,
  9. I don't recommend relying on these, they really just tell
  10. you if there's a network connection or not, they don't
  11. tell you if that network connection is actually connected to
  12. anything. For example, my computer at home is occasionally fooled
  13. because my cable modem will go out, but my computer
  14. is still connected to the router. Sometimes, computers or applications
  15. will use pings to various servers to tell them if
  16. there's a connection to the internet. But fundamentally, as a developer
  17. the only offline status that matters to you is can
  18. you get to your own servers, and of course in the
  19. cellular radio case it can be even more complex we've all
  20. had the experience of having a one bar signal. And trying
  21. to use the network. In fact, this is a critical
  22. point to offline use, and why we say you need to
  23. build offline first. You might think the way to support offline
  24. is to use the network first and then if it fails
  25. you can rely on the cash, but that doesn't
  26. really work in the real world. Precisely because it can
  27. take a long time to determine, if you don't
  28. really have an internet connection. If you only offer cache
  29. data once a network request has difinitively failed, you
  30. leave users waiting while their device desperately tries, but fails
  31. to actually transfer data over the network. This is what
  32. we mean by offline first, not that you should code
  33. offline first, but to underscore that your app has
  34. to be able to use cache data first. And then
  35. update the cache contents when it's online, but continue
  36. to use old data from the cache when it's offline.