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 )
 
Post and Bid on Joomla/PHP projects! Join EUFreelance.com for free!

Europe freelancer directory

Newsletter

Subscribe to TeachMeJoomla's newsletter
Name:
Email:


Auto tags

Leverage browser caching joomla

joomla leverage browser caching

joomla browser caching

enable google cache

joomla Use Browser Caching

joomla browser cache

joomla leverage browser cache

browser caching nutzen joomla

joomla browser caching nutzen

joomla Enable browser caching

leverage browser caching in joomla

browser cache joomla

joomla browsercaching

joomla how to leverage browser caching

joomla cache browser

browser caching joomla

meta tag expires joomla

joomla 1.5 nofollow meta

joomla http header

"browser"""security code" "write a comment"

google cache request

joomla cache enable or not