You need to understand how JQM is working. When you start on page A and go to page B, you are not really leaving page A. Instead JQM AJAX-requests page B, strips everything outside <div data-role="page"></div>
and appends this to the DOM.
This means your DOM will always stay "alive", no matter where in your application you go (unless you set data-ajax="false"
on links).
Because of this, your option 3 - global variables - should work, since the a.js
file will only be loaded on page A (and stripped out on page B, C, D...). If variables are overwritten, it will be because you are probably overwriting them - you'd need to show what's inside a.js
.
Another option would be to attach the information that should persist to the DOM directly, either using data()
(api) like:
$('html').data("foo": bar)
or if it's not that much info, just use a data-attribute
$('html').jqmData("some","thing");