Backbone.localStorage is an external file that you can use that overwrites Backbone.Sync.
You can use simple function detection, whether the user is offline or online, and then download Backbone.localStorage.js asynchronously if they are offline.
If necessary, you can also transfer a specific version of Backbone.sync your models and collections.
If you want to do both at the same time, you will have to write your own version of Backbone.sync, which calls the server and calls localStorage.
The easiest way to do this is to simply determine
Backbone.sync = function() { originalSync.apply(this, arguments); localStorageSync.apply(this, arguments); }
Edit:
As mentioned in the comments, if you use the latest backbone localStorage plugin , you can do the following
Backbone.sync = function Sync() { Backbone.ajaxSync.apply(this, arguments); return Backbone.localSync.apply(this, arguments); };
Raynos Apr 23 2018-11-11T00: 00Z
source share