Book Image

Offline First Web Development

By : Daniel Sauble
Book Image

Offline First Web Development

By: Daniel Sauble

Overview of this book

When building mobile apps, it’s easy to forget about the moments when your users lack a good Internet connection. Put your phone in airplane mode, open a few popular apps, and you’ll quickly see how they handle being offline. From Twitter to Pinterest to Apple Maps, some apps might handle being offline better—but very few do it well. A poor offline experience will result in frustrated users who will abandon your app, or worse, turn to your competitor’s apps Expert or novice, this book will teach you everything you need to know about designing and building a rigorous offline app experience. By putting the offline experience first, you’ll have a solid foundation to build upon, avoiding the unnecessary stress and frustration of trying to retrofit offline capabilities into your finished app. This basic principle, designing for the worst-case scenario, could save you countless hours of wasted effort.
Table of Contents (17 chapters)
Offline First Web Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Refactoring the item store


We've made a lot of changes to the Item store very quickly and without much attention to the code duplication or sync efficiency. Before we go further, let's refactor the store so that it's easier to change going forward.

Restricting sync to the user's lists

Right now, when we flag each database to be synchronized, we flag it for all the lists—even the lists that you don't have access to. As more people use the app, this will result in an unacceptable hit to performance. Instead, let's restrict sync to the lists that the current user owns.

Open the Item store and edit the flagStoreForSync method. Replace each usage of store with the following code:

store + '_' + me.username

Now, open the List store and edit the flagStoreForSync method here as well. Make the same substitution, but with 'list' instead:

'list' + '_' + me.username

Edit the Sync controller and modify the calculateSync method. Add the following two variable definitions to the beginning of the for loop:

var store...