Check out this example:
This file includes persistTest.js, which does all the magic. It's quite simple.
The example takes you to a second HTML page, and you can see that you're still connected. But it also works with a refresh. Refresh the second HTML page, and it will show you're still connected.