Investigating ways to prevent loss of game state

This application will be distributed in a way that users can add it to
their homescreen and launch it outside of the browser. However, on iOS,
exiting and reopening homescreen webapps causes the entire application
to lose its state, essentially reloading the page. We have no way to
pick up on this to drop the user’s save data in localStorage, so we
have to constantly save it. Right now it makes a backup of the game’s
state every 5 seconds. This will be enabled or disabled depending on
the user’s setup. It causes noticeable lag on the iPhone 5, but should
be fine on the 5S. The interval may be lowered to reflect this and make
backups more like what the user saw on the screen when they left the
application.

A number of performance tests were carried out to see whether the
deflation of localstorage data caused a speedup. It did not at all in
Safari. Safari’s localstorage is by far the fastest, and it maintains a
near-constant time for all write values up until ~16 kilobytes. Mobile
Safari is constant up until ~100 kilobytes See the jsPerf here:
http://jsperf.com/localstorage-performance-for-different-value-sizes

An option was added to disable deflation because I originally took it
out after making those tests, but put it back in when I realized that
Chrome on Android would have similar performance to desktop Chrome,
which suffers badly when writing values over a few kilobytes.