I am using jQuery 1.4 with jQuery history and trying to understand why Firebug / Web Inspector shows 2 XHR GET requests for each page load (twice as much if you visit my websiteโs homepage ( /or /#)).
eg. Visit this (or any) page with Firebug enabled.
Here's the edited / corresponding code (see full source ): -
$(document).ready(function() {
$('body').delegate('a', 'click', function(e) {
var hash = this.href;
if (hash.indexOf(window.location.hostname) > 0) {
hash = hash.substr((window.location.protocol+'//'+window.location.host+'/').length);
$.historyLoad(hash); return false;
} else if (hash.indexOf(window.location.hostname) == -1) {
window.open(hash); return false;
} else { }
});
$.historyInit(function(hash) {
$('#loading').remove(); $('#container').append('<span id="loading">Loading...</span>');
$('#ajax').animate({height: 'hide'}, 'fast', 'swing', function() {
$('#page').empty(); $('#loading').fadeIn('fast');
if (hash == '') {
$('#ajax').load('/ #ajax','', function() { ajaxLoad(); });
} else {
$('#ajax').load(hash + ' #ajax', '', function(responseText, textStatus, XMLHttpRequest) {
switch (XMLHttpRequest.status) {
case 200: ajaxLoad(); break;
case 404: $('#ajax').load('/404 #ajax','', ajaxLoad); break;
default: alert('We\'re experiencing technical difficulties. Try refreshing.'); break;
}
});
}
});
});
function ajaxLoad() {
$('#loading').fadeOut('fast', function() {
$(this).remove(); $('#ajax').animate({height: 'show', opacity: '1'}, 'fast', 'swing');
});
}
});
A few notes that may be helpful: -
- Using WordPress with standard / standard .htaccess
- I redirect
/links-like/thisto /#links-like/thisonly using JavaScript (PE)- I reach higher with
window.location.replace(addr);, notwindow.location=addr;
- , .
.