开发者

Parts of page loading at different times

I am outputting data on my website from a database. It wor开发者_如何学JAVAks fine, except when the page loads, it will start displaying in different spots and parts of the page will load at different times making the page jump around until it loads. I want it to load at the same time like most sites(Facebook, twitter, etc) and not output parts of code at different times. I am using PHP and I have no idea what is causing this. Anyone know what is happening or had any of the same problems with this?


You could try output buffering:

// before any output is generated
ob_start();

// all your code

// end of the script
echo ob_get_clean();

This will capture all output generated to a buffer, and dump it when the script has completed. However, this means that no content will be sent until your queries have completed. Perhaps another consideration you should make is optimizing your database queries as best as possible, to reduce the bottleneck impact of database hits.


In the comments on your question you said that you "fixed" this with ob_start(). It's actually not a good idea to buffer the whole page just so everything shows up at once, it hurts your perceived load time and makes your page seem slower to the user. Research has shown that slow page loads drive people away from your site. Another reason to aim for quick-loading pages is that Google has started using page speed as a signal when ranking search results.

Big fast sites like Google actually do the opposite, they flush the buffer early and often.

The reasons some fast pages seem to "load all at once" is because of things like effective page caching, load-balanced geo-located servers, using CDNs and other things like flushing the document early an post-loading content via JavaScript.

Take a look at the Yahoo! performance guidelines for more information on making your pages faster.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜