Joomla 1.5: enabling Google and browser cache

Tuesday, 13 January 2009

I just noticed upon launching a new domain powered by Joomla 1.5 that HTTP headers are designed to prevent caching and force the client (be it some crawler, robot, such as Googlebot, or a regular visitor's browser) to always request the page from the server.

This is of little use if your articles are not changing over time. Forcing the client to request from server is good for sitemaps, or pages with ever-changing hot news.

After some digging i came up with the modifications needed to allow document caching and set the Expires HTTP header.

Alternatively, this can be done by adding HTML meta tags, which provides more granularity. This core hack would probably serve old content when ajax requests are made, unless the xmlhttp javascript takes care of forcing the request or adding a random variable in order to generate an unique url for every request.

So, if you want google and your users to cache your joomla pages, go to

libraries/joomla/document/document.php

and, around line 779, change this line

JResponse::setHeader( 'Expires', gmdate( 'D, d M Y H:i:s', time() + 600 ) . ' GMT' ,true);

to

// TMJ MOD
JResponse::allowCache(TRUE);
//
 JResponse::setHeader( 'Expires', gmdate( 'D, d M Y H:i:s', time() + 1209600 ) . ' GMT' ,true);

1209600 means 3600 seconds(1 hour) * 14 days, which is 2 weeks valability for your documents. You can change that to suit your particular needs, just remember that the validity is expressed in seconds.



Give us some social love (it really works now)!

Reddit! Del.icio.us! StumbleUpon! Yahoo! Swik!



Comments (1)
RSS comments
1. Exceptions21-05-2009 20:54

Hello, 
 
Thank you for this tip. 
 
However, it should be not activated for admin and edit pages.

Write Comment
  • Please keep the topic of messages relevant to the subject of the article.
  • Please don't use comments to plug your web site. Links are rel='nofollow'-ed
  • Please refresh the page if you're having trouble with the security image code
Name:
E-mail
Homepage
Title:
Comment:

:) :grin ;) 8) :p
:roll :eek :upset :zzz :sigh
:? :cry :( :x
Code:* Code

Last Updated ( Tuesday, 13 January 2009 )
 

Europe freelancer directory

Newsletter

Subscribe to TeachMeJoomla's newsletter
Name:
Email:


Auto tags

joomla browser caching

joomla expires header

joomla browser cache

Leverage browser caching joomla

powered by joomla 1.5

"powered by joomla! 1.5"

joomla add expires headers

joomla Use Browser Caching

"Powered By Joomla 1.5"

Add Expires headers joomla

joomla expires

joomla 1.5 cache

joomla leverage browser caching

joomla cache expiration

joomla expires headers

expires headers joomla

Expires header joomla

joomla caching

use browser caching joomla

joomla browser

joomla google cache

browser caching joomla