Skip to content

Commit a5d0a29

Browse files
author
scottjehl
committed
Implemented data-prefetch attribute for anchor elements. Presence of this attribute on an anchor will cause the referenced page to be preloaded when the parent page of that anchor is shown. Fixes jquery-archive#1819.
1 parent 3dd4955 commit a5d0a29

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

js/jquery.mobile.navigation.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,18 @@
11151115
$.mobile.changePage( href, { transition: transition, reverse: reverse, role: role } );
11161116
event.preventDefault();
11171117
});
1118+
1119+
//prefetch pages when anchors with data-prefetch are encountered
1120+
$( ".ui-page" ).live( "pageshow.prefetch", function(){
1121+
var urls = [];
1122+
$( this ).find( "a:jqmData(prefetch)" ).each(function(){
1123+
var url = $( this ).attr( "href" );
1124+
if ( url && $.inArray( url, urls ) === -1 ) {
1125+
urls.push( url );
1126+
$.mobile.loadPage( url );
1127+
}
1128+
});
1129+
} );
11181130

11191131
//hashchange event handler
11201132
$window.bind( "hashchange", function( e, triggered ) {

0 commit comments

Comments
 (0)