Blogs from the team

How to setup expires header in Joomla 1.5

Expires header in Joomla 1.5A first-time visitor to your page may have to make several HTTP requests, but by using the Expires header you make those components cacheable. This avoids unnecessary HTTP requests on subsequent page views. Expires headers are most often used with images, but they should be used on all components including scripts, stylesheets, and Flash components.

There are two aspects to this rule:

  • For static components: implement “Never expire” policy by setting far future Expires header
  • For dynamic components: use an appropriate Cache-Control header to help the browser with conditional requests

By default on a Joomla fresh installation the Expires header will look like below, when you analyse the tool in google web master “Expires: Mon, 1 Jan 2001 00:00:00 GMT”, which means the browser will never cache these files because the expiry date is set to Jan 2001. If your server is Apache, use the ExpiresDefault directive to set an expiration date relative to the current date. This example of the ExpiresDefault directive sets the Expires date 10 years out from the time of the request. ExpiresDefault “access plus 10 years”

Using a far future Expires header affects page views only after a user has already visited your site. It has no effect on the number of HTTP requests when a user visits your site for the first time and the browser’s cache is empty. Therefore the impact of this performance improvement depends on how often users hit your pages with a primed cache. (A “primed cache” already contains all of the components in the page.)

The best component that can take care of the expire header feature is “Expires Headers” and is available for FREE!

YSlow and Pagespeed look at Expires Headers when evaluating your site. This plugin allows an administrator to set global Expires, Cache-Control and Pragma headers, as well as individual settings (inclusive or exclusive) for particular menu items. You can download the Plugin here >>

 

Note: Expires Headers cannot alter the expires headers for content that was not processed through the Joomla framework. This includes CSS files, Images, Favicon files and others. These files can be addressed using htaccess rules

Below is the code that will set your expires headers for these file extensions ahead 10 years. you will have to add this to the .htaccess file in your website.

<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Wed, 15 Apr 2020 20:00:00 GMT"
Header set Cache-Control "public"
</FilesMatch>

Alternatively, to setup relative dates you can use

# turn on the module for this directory
ExpiresActive on
# set default
ExpiresDefault "access plus 24 hours"
ExpiresByType image/jpg "access plus 1 months"
ExpiresByType image/gif "access plus 1 months"
ExpiresByType image/jpeg "access plus 1 months"
ExpiresByType image/png "access plus 1 months"
ExpiresByType text/css "access plus 1 months"
ExpiresByType text/javascript "access plus 1 months"
ExpiresByType application/javascript "access plus 1 months"
ExpiresByType application/x-shockwave-flash "access plus 1 months"
Share on Facebook0Share on Google+0Tweet about this on TwitterShare on LinkedIn0