Notes about PersistJS

After I tried to use PersistJS, I am impressed. Then people are asking me to write-up my findings. So, here are my notes about PersistJS:

The first recommended reading is Why This is Awesome section. It makes a good case why you should use PersistJS. One interesting aspect of PersistJS is explained in its README: “Each backend is wrapped by PersistJS and exploses the exact same interface, which means you don’t have to know or care which backend is being used.” This means that you are not limited by a single technology and this enables you to adopt to a different storage easily. This statement might leave you with the question about which one does PersistJS choose? To answer this question, I found the order which PersistJS chooses a back-end store:

  1. gears
  2. localstorage
  3. whatwg_db
  4. globalstorage
  5. flash
  6. ie
  7. cookie

In my first implementation that uses PersistJS, I did not load extras/gears_init.js or extras/swfobject.js, this means that google gears and flash back-end stores are not enabled in my use of PerisstJS. With this setup, localstorage becomes the first one that persist JS attempt to store data.

PersistJS uses HTML 5 localStorage DOM attribute to implement its localstorage storage. HTML 5 is a new specification in draft state now. localStorage is one of the two storage mechanisms introduced, which “is designed for storage that spans multiple windows, and lasts beyond the current session.” The the storage format that HTML 5 exposes are key/value pairs. Both keys and values have to be strings. For further reading, see specification draft.

If you are an Ext JS user, you can use PersistStateProvider to persist UI state and application data.

4 thoughts on “Notes about PersistJS

  1. Hi,
    I m really impressed by PersistJS but i really could not make run in FF, i checked with different OS, including XP, Win Server and Vista, as i heard that there is issue with PersistJS with FF.

    Could you please help me out?

    Any suggestions will be appreciated.

    1. I’m having the same problem right now and have emailed Paul about it. I’ll reply if I hear anything. I can get persistence in all BUT FF (3.6.16).

  2. Hi!

    I’m actually using PersistJS too and I got a little trouble.

    Can we use the attribute “length” to know the number of keys in the Store that we are using?

    Why the method key(number) doesn’t work giving the content of the key here listed???????

    Do you have any idea of how can I do that? Any suggestion will be absolutely appreciated.

    THANKS!!!!!!!!!!!!!!!!!!!!!!!

Leave a comment