The push notification is discarded because when refreshing the browser window, the current state (including the entire DOM) is discarded. You need to persist the message either on the server-side or the client-side.
If you already use a form of sessions, you could write the messages into your the active session. Or if you already store the notifications at some point before submitting them, you could simply delay removing them from that storage (either for a certain amount of time or until the user dismisses them, sending an event back to the server) and re-send all stored notifications on each initial connection.
But because you say you want to avoid writing to a db, I assume this is out of the question.
The traditional solution to storing state on the client-side is to do so using cookies. You can set cookies on the client-side as well by manipulating document.cookie
, but that's a bit ugly.
The more modern approach is using localStorage (a domain-and-port-specific key-value storage supported by most modern browsers) or its brethren. If you don't want to rely on HTML5 support (e.g. you're dealing with IE6 users), then there are plenty of solutions that offer a wide range of abstractions around the various equivalents. Note that with IE8 and below the storage size may be very limited, so be careful what kind of data you dump into it.
If you are comfortable restricting support of this feature to users of modern web browsers and want to remain within jQuery, there's even a jQuery plugin for that, which provides a wrapper around both localStorage
and sessionStorage
.