Constant Updating of Local Storage while A User is Online

I have built an app which relies on retrieving data from Firebase to show to the user. However, I want this app to be usable when the user is offline too, so I have used the {preservesnapshot : true} setting when I retrieve my data so that I can unpack the FirebaselistObservable for my data and store my data into an array. After this, I unpack this into my local storage. However, my problem is that I want to recursively store the data by unpacking the firebase information say every 5 minutes. By using a while loop and setInterval(), my app seems to freeze when I enter my page. Is there any convenient way in which I can check if the user is online every 5 minutes and then store data into the local storage without crashing the application?