I'm working on a web app with an auto-saving feature. I use something like that for managing backup:
setInterval(function(){
localStorage.setItem('save', data)
}, TIME_INTERVAL)
Each save replace the previous one.
Can you tell me a reasonable value for TIME_INTERVAL?
I don't really know the impact on the client side. I'm looking for technical answers, in the user point of view, a permanent save is the best for him but a delay can be tolerated if needed.
I even did some tests with TIME_INTERVAL = 1
and didn't see any issues on my browser but this seems insane to write data on the client-side every millisecond... What's do you think? Should I save the data every second or this is a really bad idea?
These are some things in the client that get affected if you set the interval too short:
localStorage.setItem()
is pretty fast).So, since all of these are negatives in some ways, you should not be setting the interval time shorter than you practically need it to be set. You will find that many other applications (such as StackOverflow or Google docs) do an autosave in a few minutes AND they don't do another auto-save until after the underlying data has actually changed.
Unless you have a particular compelling case for saving more often than every few minutes, I don't see why you should go shorter than that. And, it would really, really help battery life if you don't even run your timer until the underlying data has actually changed.