Load jQuery Mobile script asynchronously?
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
You can load jQuery Mobile without blocking initial page parsing, but you cannot treat it like an independent script. jQuery Mobile depends on jQuery, and many projects also need to register mobileinit configuration before jQuery Mobile executes, so the real problem is preserving order while still avoiding parser blocking.
Why Plain async Usually Fails
If you place two independent async script tags on the page, the browser can execute them in whichever order finishes downloading first. That is fine for unrelated scripts, but not for jQuery Mobile:
- jQuery must exist before jQuery Mobile runs
- '
mobileinithandlers must usually be attached after jQuery loads but before jQuery Mobile loads'
So the direct answer is: yes, asynchronous loading is possible, but not by sprinkling async on both files and hoping the order stays stable.
The Safest Static Option: defer
If the scripts are known at page load time, defer is often simpler than async. Deferred scripts download without blocking HTML parsing, and they execute in document order.
That already solves most "load asynchronously" goals because the browser does not block parsing while the files download.
If You Need Dynamic Loading
If you truly need runtime loading, load the files sequentially in JavaScript. The example below waits for jQuery to load, registers the mobileinit hook, then loads jQuery Mobile.
The async attribute is still used on the dynamically created script elements, but sequencing is now controlled by the promise chain instead of by network timing.
What to Configure Before jQuery Mobile Loads
Many legacy examples forget the configuration timing. If you need to change jQuery Mobile behavior, define that setup before the library executes. In dynamic loading, that means:
- load jQuery
- register
mobileinit - load jQuery Mobile
If you reverse steps two and three, the configuration may be ignored because the framework has already initialized.
Performance Reality Check
jQuery Mobile is a legacy library, so performance wins from clever loading are usually smaller than wins from reducing page size, image weight, and unused widgets. Script order bugs are far more common than genuine network bottlenecks in old jQuery Mobile codebases.
That is why defer is often the best engineering choice. It is simpler, easier to debug, and already non-blocking for HTML parsing.
Common Pitfalls
- Using plain
asyncon both jQuery and jQuery Mobile and assuming dependency order will hold. - Registering
mobileinitafter jQuery Mobile has already executed. - Treating
asyncanddeferas interchangeable. They solve different ordering problems. - Dynamically loading the script but forgetting error handling, which makes failures look like random undefined-symbol bugs.
- Optimizing script loading while ignoring the larger cost of heavy page markup, images, or obsolete widgets.
Summary
- jQuery Mobile can be loaded without blocking parsing, but dependency order must be preserved.
- For static pages,
deferis usually the simplest and safest answer. - For dynamic loading, load jQuery first, then register
mobileinit, then load jQuery Mobile. - Plain parallel
asynctags are unreliable for dependent libraries. - In legacy jQuery Mobile apps, correctness usually matters more than squeezing out tiny loader optimizations.
Related reading
- loading js files and other dependent js files asynchronously
- Loading Model only once in fastAPI
- Loading SavedModel is a lot slower than loading a tf.train.Saver checkpoint
- Loading sentence transformer model in streamlit taking FOREVER
- Load XDocument asynchronously
- Lock-free algorithm library
- Load local html into UIWebView using swift
- Load resources from relative path using local html in uiwebview

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.