Note that there are some explanatory texts on larger screens.

plurals
  1. POOptimizing code for jQueryMobile: problems with selectively including external JS files only when they are needed
    primarykey
    data
    text
    <p>I am using jQueryMobile for a mobile application. Obviously I want the UI to load very quickly, but the application has more than one tool so I want to only load the relevant external JS libraries for the 'pages' when they are navigated to. For the main application (90% of the pages) I just want the jQueryMobile core files (i.e. the latest jquery core from the Google AJAX libraries and the jQueryMobile JS &amp; CSS). However, for the remaining 10% I need Google Maps v3 with geolocation enabled (so the Google Gears external library) and the MarkerClusterer library (I have >400 markers that I want to plot only if I have to).</p> <p>As I understand how jQueryMobile works (all via internal AJAX requests), you <em>must</em> have all the libraries for the whole application load when the application initializes. This makes my application <em>really</em> heavy when the user first requests the mobile site (all core files, plus all maps/gelocation/marker cluster files). I want to avoid that happening, as it will scare many potential users away (especially when only a subset of my users want the geolocation goodiness).</p> <p>I have tried loading just the Google Maps components at the end of the relevant page (before the footer div) and also tried putting them into the &lt;head&gt; tag in the relevant page. However both these fail to initialize (checked with console.log() output attached to the functions).</p> <p>And yes, before you ask, I am using the "pagecreate" live() function and am addressing the correct div (If I put everything related to Google Maps into the root page head tag everything works just fine as it should)</p> <p>I feel like this must be a pretty common question: selective loading of page components with jQueryMobile. I couldn't find anything online via Google - most jQueryMobile tutorials are the common garden 'Hello World!' variety, so if you have anything to offer I am all ears! Links to selective loading tutorials also welcome!</p> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload