Thursday, December 15, 2011

jQuery Mobile single-page vs multi-page template

[Updated 2012/02/09]
In my recent posts I mentioned about jQuery Mobile single-page and multi-page templates, so what exactly are the differences between them?

Single Page Template:

Launch - example from previous post, notice the address shown as you navigate
  • Lighter and cleaner. Each page is a separate html file and more modular. 
  • Better fallback if JavaScript is not supported. So works well on more platforms, you could even target grade C browsers 
  • On first load, the start page is loaded into the DOM. An internal reference is always held to this. Any new page loaded is added to the DOM. Any previously shown page is removed from the DOM. The start page is always in the DOM.
  • The DOM size is relatively smaller
  • Optional to use the "page" data-role element in the code
  • Can turn off Ajax Navigation between pages using data-ajax="false"
  • Recommend to use the <title> tag for page titles
  • The <title> tag always gets precedence during page loads
  • Consumes more bandwidth as each page navigation generates a new request
  • Navigating back to a previously loaded page will again generate a fresh request (with DOM caching you can avoid reloading of the same pages multiple times)
  • First load is faster, but every subsequent page has to be fetched
  • Suitable for larger applications and situations where you want to target as many platforms as possible including platforms which lack JavaScript support

Multi Page Template:

Launch - example from previous post, notice the address shown as you navigate
  • Heavier. All the pages are in a single html file.
  • Needs JavaScript support as Ajax Navigation is used
  • Multiple page containers are present, and only the first one is shown when page loads
  • Large applications with many pages will increase the DOM size
  • The "page" data-role element is required
  • Using data-ajax="false" for internal pages ignores the data-transition attribute, by default slide is used
  • Recommend to use the data-title attribute for all page titles
  • On first load, <title> tag is used and subsequent transitions data-title is used for page titles
  • Since all pages are already loaded, no additional requests are generated for navigating between pages
  • First load is slower as the file size is larger, but subsequent page navigation is fast
  • Suitable for relatively smaller applications and situations where you know the capabilities of your target platforms including presence of JavaScript support


  1. So when should you use what? Why is single page cleaner?

    You make it sound like Multi Page is not good for anything.

    1. Gabbsmo, Multi-page is definitely useful, I didn't intend to sound like one should never use multi-page. Thanks for the feedback :), will update this page by EOD.

    2. Check the documentation in this page, even jQuery Mobile website recommends single page template apps:

    3. Multipage temaplates are superfast and looks way better than single page templates especially on mobile browsers and mobile apps.

      biggest usage of multipage template is developing hybrid apps, which gives rich UI.

  2. this really good thanks for ur help good going

  3. I have run both of your examples with the latest JQuery code and data-transition does not work as slide on either when used on the 'a' tag. I have tried changing the global defaultPageTransition setting to none and slide (fade is now the default, not slide) and slide still doesn't work. This behavior is seen on code > 1.0.1. Any idea why this is happening?

  4. Never mind. It works on a phone but not in a web browser. Not sure why the earlier JQuery works in browsers.

    1. Hi, Thanks for bringing this to my notice .. will fix it and also this is a reminder that I have to update all other posts to reflect v1.3.1 and changes :)

  5. In both case what if i want to manage common navigation header/footer in all pages and having some scripting code in it, then how can i manage it?

    1. Hi Amit, script to do what? can u give an example/code snip where u tried this and faced issues

  6. Nice article! Pretty helpful. What if I have a common header and footer with a navigation in a single page instance, and I want to use a common DOM/script for them as those has to be similar through out the pages.

  7. nice article, thank you Chetan!