I
start with a pretty standard index.html site which loads JQM and all
other scripts. Since this is always the first page when someone starts
the app, I don't need to include this stuff in all other sites. At least
that's how I would expect this to work, but sadly JQM doesn't work that
way.
Not quite sure what you are saying here, but I will try to guess.
I'm guessing you are complaining because you think you have to include all the the CSS and scripts in the
<head> section of every page, and because you think there's something horrible about that, and you think you have to concoct some elaborate scheme to "fix" that.
If you do this correctly - simply place links to your CSS and JS files in
<head> (rather than having exhaustive CSS and JS content within
<head> directly) the overhead is negligible, especially in a native app where a webview is retrieving pages from the local file system.
JQM ignores
<head> content (other than title) on all but the entry page. So, the webview retrieves maybe a couple thousand extra bytes that don't need to be retrieved, and then JQM throws it away. The resources (JS and CSS) are NOT loaded on every page. Everything in <head> except for the title is stripped away, and JQM puts the page content into the DOM.
The overhead is negligible, and the user will never notice the difference. I doubt that the difference would be even 1mSec.
But if this bothers you anyway (after all, this does increase the size of your app, and if you had several hundred short pages in your app, perhaps
<head> could add 10% or more), you can simply omit it on all but the entry page. It will work just fine. JQM is going to ignore it anyway. In fact, I do this myself in Phonegap apps. Problem solved. Just have an empty
<head>, optionally with
<title> if you wish. (Probably is no use for
<title> in your PhoneGap app, so just empty
<head>.)
The reason this is repeated on every page is in case the user hits the browser refresh. In a Phonegap app, it isn't possible for the user to refresh the browser, and so repeating CSS and JS in the
<head> of every page is not necessary. Just leave it out.
The only case where it would be necessary would be if you use
data-ajax="false" or
data-rel="external" on one or more links. If you are doing this, either you are misunderstanding JQM's Ajax model, or else you are trying to use some JS that wasn't designed to work with JQM. I don't recommend the latter. Stick to stuff that works with JQM, because if you use
data-ajax="false" or
data=rel="external", you are abandoning one of the major benefits of JQM.
You're trying to solve a "problem" that doesn't need to be solved.
When you link to truly external pages, I recommend that you open them in the device's browser, outside of your app - just use
target="_blank".
If you are creating a site that might be used in a PhoneGap app, and also on the web, then you can use a static site generator (I use Middleman) and have it produce different builds for each scenario. You can easily produce a version with
<head> content on every page for the web, and an alternate version with
<head> content only on the entry page for PhoneGap.