I am using jQuery mobile in single page template (Each page is a separate html file). I want to prefetch a page that load content via Ajax. I put the prefetch code in Document.ready() function in first page
$.mobile.loadPage("my-projects.html", { showLoadMsg: false });
ajax call inside the Document.ready() function of second page which i want to prefetch. This ajax call is not happening when we preftech that page. Is there a way to achieve this. Please help
Prefetching is the process of retrieving and caching content before it has been requested by the user, and when used intelligently, it can speed up the user's experience with your mobile app.
Multiple pages can be included in the single jQuery mobile document which loads together by adding multiple divs with the attribute data-role = "page". The div with data-role = "page" should consist unique id to link internally between the pages.
The content of pages in jQuery Mobile is completely open-ended, but the jQuery Mobile framework provides a number of helpful tools and widgets — such as collapsible panels and multiple-column grid layouts — to make it easy to format your content for mobile devices. Basic HTML styles. Layout grids (columns)
jQuery Mobile is a HTML5-based user interface system designed to make responsive web sites and apps that are accessible on all smartphone, tablet and desktop devices.
jQuery Mobile has prefetching built right in, all you have to do is add the data-prefetch
attribute to a link that links to a remote page:
<a href="prefetchThisPage.html" data-prefetch> ... </a>
Source: http://jquerymobile.com/demos/1.1.0/docs/pages/page-cache.html
In a general sense, when you pull-in a page via AJAX, the document.ready
function will not fire. You can however use jQuery Mobile Page events such as pageinit
. For example:
$(document).delegate('#my-page-id', 'pageinit', function () {
$.mobile.loadPage("my-projects.html", { showLoadMsg: false });
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With