Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

When you browse repositories on github ( for example https://github.com/mojombo/jekyll/tree/master/bin) it feels like it uses ajax and does not reload the whole page every time. However the url really changes (not just after the # ).

I already found this article where they write about their backend: https://github.com/blog/530-how-we-made-github-fast

But is this really the whole trick?

My pages never feel that fast and I am already using yslow to optimize it.

share|improve this question
    
Not so fast in IE8 it seems, which I assume does not support this HTML5 feature. In IE8, when the URL changes the entire page appears to be refereshed. –  w3d Sep 4 '11 at 17:04
    
@w3d I think GitHub is either assuming that you're progressive enough to use something other than IE if you're using git. They may also just have decided not to support IE. –  sholsinger Sep 7 '11 at 18:20
add comment

1 Answer

up vote 7 down vote accepted

The URL change is a mix of an old feature of HTML when calling an A tag with hashes,

<a href="#home">Go to my home</a>
<p>TextTextTextTextTextTextText</p>
<a id="home">

that makes possible linking parts of the same page without reloading at all, and a new HTML5 JavaScript window object

window.onhashchange

This new object it's a event handler, that fires when a link with hashes is clicked, so it's possible to handle that event with JavaScript and possibiliting browser history and back buttons. Here's a exemple

function hashChanged() {
    if (location.hash === "#home") {
        showPage('home');
    }
}

window.onhashchange = hashChanged;

Mozzila Developer Network window.onhashchange Page

jQuery hashchange event cross-browser plug-in

share|improve this answer
    
But github has no hash in the url. How is this done? –  peq Sep 4 '11 at 14:54
3  
ok, found it: spoiledmilk.dk/blog/… –  peq Sep 4 '11 at 15:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.