Why my site is “rocking” when it is being loaded? seems to be a question not being asked enough. Even in digg.com, the capital of nerddom, the site rocks after it content was loaded to show an infomercial at the top of the page.
It is annoying because you actually start reading, or at least scan the page, when the text start to show. When the page “rocks” it disorients you, and you have to search for the location of the text you were reading.
It used to be caused by images embedded in the HTML code. When the browser reads gets to an IMG tag when parsing the HTML, it has no way to know what are its height and width, until after the image was fetched from the server, and therefor how much visual space it should reserve for it.
This impacts the browsers decision where to place the other items of the page, and when finally the image is loaded the browser finds its height and width and has to recalculate the position of the other elements on the page (a process also known as reflow).
The cure for this is very simple – in most cases you know in advance what is the expected dimension of the image when it is an integral part of the design, or you can use some library to calculate if it is stored on your server, therefor you can set the width&height attributes of the IMG element or specify it in a CSS style rules. This leaves as a problematic issue only the situations in which you embed an image which is located on other server not controlled by you, but this probably happens very rarely for most of the sites.
AJAX scripts are another cause for “rocking” . The main reason for AJAX “rocking” is post loading of dynamic information, usually done when the site serves static HTML pages, probably because of performance related reasons, but needs to show some dynamic content, and therefor loads it after the page was loaded.
As with the images, you simply have to specify the height and width in advance – since the target area for the data received from the AJAX operation is usually a DIV, just specify its height and width.
Note: There is a fundamental difference between rocking when the page loads as result of AJAX, and “rocking” when page changes as result of AJAX. When the page “rocks” after a user initiated an action, the user is idle while waiting for the page to change, and therefor the “rocking” is not as annoying (especially if you conceder that the alternative is full page load).