Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Twitter display my profile instantly?

Context

I realized that in Twitter, the profile page is displayed in different ways depending on how it is called:

  1. By clicking the profile link in the menu, the DOM and the latest tweets are loaded, and the page is displayed in ~4 seconds. Each time.
  2. Using the keyboard shortcut GP (or the link on the left), the page is displayed instantly.

Details

  • I noticed that the profile must have been recently displayed for GP instantly displays the page.
  • By closing and opening the browser, the profile must be displayed again for GP instantly displays the page.

Investigation

So at first I thought Twitter could use a serverside session variable to store data. Then I discovered a use of localStorage in the Twitter source code. I confess, DOM storage is unfamiliar to me and the Twitter JavaScript code is unreadable. So I don't sure they use localStorage to store the profile.

Question

Any hypothesis, infos or links about Twitter DOM storage / session storage?

like image 440
GG. Avatar asked Feb 21 '12 23:02

GG.


1 Answers

This is an interesting question, so I went to twitter, and did some investigation myself.

Clicking on my profile name, the link is done with AJAX. I see my timeline getting downloaded. But, the page is already loaded in advance, so my information is also already downloaded.

By clicking on the link on the left, or with GP you just display the page already loaded (hidden, or in JavaScript object, so in memory). It will just display your profile already downloaded, and by AJAX download the feed (JSON).

The URL will change from https://twitter.com/#!/ to https://twitter.com/#!/wraldpyk (in my case).

When you click your profile in the menu (top right) you go to https://twitter.com/wraldpyk. This will re-open the page, and will download everything. Note you will get redirected to https://twitter.com/#!/wraldpyk, and meanwhile your timeline also gets downloaded (open FireBug and see the images and feeds getting downloaded)

As far as I can tell, no local storage (except in JavaScript, like everyone does) is done. All data is constantly downloaded on new page load.

Same thing happens when you type gh when on your profile. (And also with all other shortcuts)

like image 74
Rene Pot Avatar answered Sep 22 '22 17:09

Rene Pot