Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should the website main page be cached?

To my knwoledge, caching should be ONLY enabled for static contents of website, and we use no-cache for dynamic pages. The website main page is the most dynamic page as contents are regularly updated. Strangely, I found that major websites set a short cache maxage for the main page too. Google set 3 seconds, stackoverflow 21 seconds.

More strangely (to me), when analyzing the performance by WebPageTest.org, it considers the main page as a static content, and expects a long cache lifetime. For example, you'll receive a FAILED notice for short 21s cache lifetime of stackoverflow.com. Check HERE. Even for 2 hours, you'll receive WARNING.

How the main page and other dynamic pages should be cached?

like image 574
Googlebot Avatar asked Mar 26 '12 08:03

Googlebot


2 Answers

Any page should be cached if it's useful to do so - whether static or dynamic. Not caching dynamic pages becomes suicidal when running a high-traffic site, as the unnecessary repeated requests will bring the site to its knees.

Of course, it all depends on the expected update frequency, which will differ not only from site to site, but also from page to page: if your "about us" page might change once a week, there is no point in making it expire in 1 minute; OTOH, if the frontpage changes every second, it may be useful to set its expiration time to 21 seconds, as the update latency <1 min is acceptable, yet the 20 seconds where a refresh doesn't necessarily send a HTTP request are quite useful for lowering load.

In other words, there is no hard rule, handed down on stone tablets from Mount Sinai, saying "Thou Shalt Cache The Front Page For One Day", nor "Thou Shalt Not Cache Dynamic Content" - it depends very much on the specific situation of a site.

like image 169
Piskvor left the building Avatar answered Oct 04 '22 03:10

Piskvor left the building


Ideally, you should cache everything including the dynamic pages as well. Static pages/resources can be cached with a very high max-age as generally they wouldn't change that often and even if they do change, you could change the request url (by adding QS) to avoid the cache entry. Caching dynamic pages is a bit tricky as the content changes quite frequently. If possible you should try implementing If-Modified-Since for the dynamic pages, where in the If-Modified-Since is the timestamp of the last time your page or the sub-section was changed. Generally, If-Modified-Since would be a DateModified timestamp column in your database for that particular entity. If your page is being composed of multiple db entities, then If-Modified-Since would be the min of DateModified for those entries. Implementing If-Modified-Since is actually a bit of hassle so a lot of people just leave their dynamic pages as is but do keep in mind it is really helpful if your page/site is pretty popular and crawled by SEs quite often.

like image 22
Sachin Avatar answered Oct 04 '22 03:10

Sachin