Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery mobile prefetching a page that load content via Ajax

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

like image 783
Ajmal VH Avatar asked Jun 15 '12 13:06

Ajmal VH


People also ask

What is content prefetching?

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.

How do you include multiple pages in the single jQuery Mobile document explain with an example?

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.

What is content in jQuery Mobile?

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)

What is jQuery Mobile page?

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.


1 Answers

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 });
});
like image 153
Jasper Avatar answered Sep 27 '22 22:09

Jasper