How AJAX is done in github source browse?

Github has a really nice source browser. Navigating between different paths in the repo generates ajax calls to load the content (as you can clearly see in the firebug log). The ajax call returns the html of the new list of files to be displayed. In addition to changing the view list of files, the url changes as well. However it does not use fragments like most ajax deep-linked sites (use of #). At github the whole url changes.

For example at django repo at https://github.com/django/django going to django folder will generate ajax request to https://github.com/django/django/tree/master/django?slide=1&_=1327709883334 which will return the html content of the folder. The link will also change to https://github.com/django/django/tree/master/django. As you can see this new link does not use a fragment.

How is that done? I always thought that ajax based sites have to use url fragments (#) to achieve deep linking but apparently it is not so.

Answers


Well, as was described in the comments by Dav, it appears that GitHub does not use the pAjax library. Due to the fact that I ended up answering with an "incorrect" information (actually I think I had seen something related to GitHub using pAjax when I was answering this question, but at the moment I can not find the source), I went after the correct answer.

I did not find anything official on the part of developers regarding whether any library was used, only found a post saying that the History API was used: https://github.com/blog/760-the-tree-slider

Then came to my head, why not ask the code itself?

Using Chrome (in reality any browser with a decent developer tools), open a repository (in this case, pAjax), right-clicking on any directory, simply choose inspect element.

This will display the a element responsible for the directory link.

A "suspect" class showed up, let's search for it on the javascript source of the page.

And here it's, the click event handler for the directory link, in addition to the entire code related to the animation and the History Api. And as can be noted, it's not used any library behind the History Api. Don't forget to mark the Pretty Print option.


Old and incorrect answer

GitHub uses the jQuery plugin pJax (pushState + Ajax), which uses the HTML5 history API.


You have to use HTML5's pushState() method to change browser history.

window.history.pushState(data, "Title", "/new-url");

Doc says:

pushState() takes three parameters: a state object, a title (which is currently ignored), and (optionally) a URL.

The last argument is the new URL. For security reasons you can only change the path of the URL, not the domain itself. The second argument is a description of the new state. And the first argument is some data that you might want to store along with the state.


Need Your Help

How to make GET and POST request from servlet with content type and content

java servlets httprequest servlet-3.0

I want to make GET and POST requests from a servlet to another server, where I will be sending XML content and a Content-type header.

How to add a downloadable folder to my html document?

html web folder

I have a small question on how to add a folder that can be downloaded from my website. Would I call the file like how I normally call everything else (pictures, videos) and just make an: