1

How can a page be reloaded with a new URL and the corresponding contents smoothly, so that the header does not flicker? For instance if on Twitter I click the menu items Home, Connect, Discover, the header stays displayed, no flicker. The only way I know this can be done is using Javascript, but Javascript cannot change URLs. What is the magic behind Twitter's website?

ideaboxer
  • 3,083
  • 6
  • 36
  • 57
  • Thanks, your answer is useful in that you mention AJAX. But I still have to find out how to change the URL. This is not clear to me. – ideaboxer Dec 20 '12 at 00:23
  • http://stackoverflow.com/questions/136458/change-the-url-in-the-browser-without-loading-the-new-page-using-javascript - here is how. –  Dec 20 '12 at 14:55
  • The answer with 119 upvotes, does that work for you? –  Dec 20 '12 at 20:31
  • Yes, I think it will work that way. Thanks again! – ideaboxer Dec 23 '12 at 22:12

2 Answers2

0

You could use history.pushState to manipulate the currient url. And reload the page with ajax functions.

rekire
  • 45,039
  • 29
  • 149
  • 249
0

They are simply using ajax.

The header does not flicker because it does not change. The ajax call ask for data, and when it gets it, it inserts it into the body.

For the body,

You could use an effects function to fade in the new content if you do not want an abrupt change when it is ajaxed in.

If you want to load your static data in one upload, you can then flip through static content using the CSS display property.

You can see that the browser is not loading a new url because there is no indicator.

Also, you can see the ajax indicator for twitter is running.

To keep a history of your ajax calls use info. from this post:

For ajax - Hashes vs HTML 5 History API?

For Twitter:

They are using CSS to flip through the page as the ajax indicator and the load indicator do not light up after the initial ajax call.

You can verify that they are using history by doing window.history.back() in the console.

To change the URL dynamically see:

Change the URL in the browser without loading the new page using JavaScript

Community
  • 1
  • 1