Michael has an explanation of how the itunes sale counter works using AJAX. This reminded me of the storage space count on the gmail page (if you have an account on gmail you may not see the dynamic counter unless you logout).
I won’t give a full walkthrough, as I’ve only spent about 30 seconds looking at the code. But the gmail counter is a bit simpler than the apple version, probably due to the fact that google completely control the rate of growth. This allows them to rely only on static data served with the page (they’ve scheduled/estimated the amount of storage that will be available at some times in the future), and then they simply use linear interpolation based on the current time.
For example, my page was served with the static data defining the [time, capacity] pairs:
1 2 3 4 5 |
|
For the curious, these entries correspond to the start of June, July and August respectively. I expect as it approaches August, they will start serving pages with an entry for September.
The update code simply finds the relevant entry in the CP
array, and then interpolates based on the current time.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
This is a good illustration how precomputation can avoid trips to the server. Although, since it doesn’t use a roundtrip, I guess it doesn’t count as AJAX at all…