The Joomla! Community Magazine™

Increase your site's speed dramatically

Written by | Tuesday, 01 March 2011 00:00 | Published in 2011 March
As you all know – Joomla!'s page loading speed is not one of the main advantages of the system. Of course, there is some advice you could follow and there are two very important things that needs to be done:
Increase your site's speed dramatically http://www.psdgraphics.com
  1. First thing is system plugins order, which should keep following order:
    • "System - cache" plugin should be last one in the list
    • all SEF plugins must be loaded right before cache plugins
  2. Create new .htaccess file or edit the one you have in your JOOMLA ROOT folder and paste this:
### @version $Id: htaccess.txt 10492 2008-07-02 06:38:28Z ircmaxell $
# @package Joomla
# @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
# @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
# Joomla! is Free Software
##

## Can be commented out if causes errors, see notes above.
Options +FollowSymLinks -Indexes

#
# mod_rewrite in use

RewriteEngine On

########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a tag in URL
RewriteCond %{QUERY_STRING} (\|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
#
########## End - Rewrite rules to block out some common exploits

# RewriteBase /

########## Begin - Joomla! core SEF Section
#

RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

#
########## End - Joomla! core SEF Section

SetOutputFilter DEFLATE
Header set Expires "max-age=29030400, public"
Header unset ETag
FileETag None

ExpiresActive On
ExpiresDefault A600
ExpiresByType image/x-icon A2592000
ExpiresByType application/x-javascript A604800
ExpiresByType text/css A604800
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType text/plain A1200
ExpiresByType application/x-shockwave-flash A2592000
ExpiresByType video/x-flv A2592000
ExpiresByType application/pdf A2592000
ExpiresByType text/html A600


After tests we've done, the Joomla! 1.5 site with over 6 000 news items, loaded its content in less than 2 seconds, compared to more than 5-10 seconds before.

Read 62581 times
Tagged under Administrators
avatar
Stephen Brandon Tuesday, 01 March 2011
Gregor,

Thanks for writing about these issues, but it would have been useful to include some more information here about the implications of this setup. Can I suggest a few things I wished I read?

1 - I guess you're assuming that the system cache plugin is going to be turned on?

2 - what about the cache in the Global Preferences? What effect does it have? Does it work in conjunction with the system cache plugin or not? Which is more effective in certain cases? There are also some alternative (though similar) plugins available that allow more control.

3 - what are some of the implications of setting ExpiresByType for different MIME types? Even a link to further information would be useful.

4 - do the ExpiresByType directives for text/html apply to dynamically generated Joomla pages? If so how does this sort of caching interact with the other caching e.g. the system cache plugin?

5 - what are the implications for any of this sort of caching for sites with dynamic content? e.g. displaying current date/time on the page, or random page elements, or personalised contents for logged-in users etc?


Ok, you probably just wanted to write a basic article on a technique that has worked for you, and that's fair enough… anyone care to write an article expanding on this?
VOTES:-1
avatar
SetOutputFilter DEFLATE

The line above is causing a page error 500.
Any idea why?
VOTES:3
avatar
I tried this for my website, but this led to an Apache server error. This is strange, since my old .htaccess file has no problems with the server.
VOTES:2
avatar
WOW!!!!

Just tried it and my site is lightning fast now, even in ie, where it was lagging before!!!!!! just created a new htaccess and pasted in everything you have in blue.

Thank You!!
VOTES:1
avatar
It might have been helpful to also mention that your apache configuration must have both headers and expires modules enabled for this to work. These are not enabled by default.

To enable the modules use the following:
a2enmod headers
e2enmod expires

You will then need to run:
/etc/init.d/apache2 reload
VOTES:1
avatar
@Stephen

1. Yes
2. Best is if also turned on. We haven't tested it with other alternatives. It works well with the core cache (global setting and plugin).
3. Implications may occur if you edit articles and change images often or you generate these on the fly.
4. It applies to all pages once loaded. It does not interact directly with the cache plugin, but the combination above really speeds all sites we tested it on so far.
5. Implications could occur for modules mainly. If you are using modules that are expected to display different information each time, I would suggest to turn off caching for these modules from its parameters. If it doesn't supports it, I would suggest altering the module (it is really 2 lines of code in the XML). So the caching basically may impact in showing same content in "random module", so for such it should be off.

Honestly, we are sharing information that we needed and used on client projects and it works. It has implications, but the subject is so large that for details on each project a lot of time should be spent. I suggest you to "try and learn from the results". If you have a large project, probably it is a good idea to implement it on some smaller to see the expected results - that is honestly what we did before applying on large scale sites.

@abang and @Kraakman
Remove SetOutputFilter DEFLATE from .htaccess or the lines after it one by one till it works. Or contact your hosting provider to enable that directives.
VOTES:0
avatar
Grigor,
Thank you for your article. I have also tried your .htaccess and it produced Server Error 500, while my existing .htaccess works with no problem.
I am always more than eager to try anything which could speed-up my Joomla sites, and I will not dismiss your approach, especially because it's published in respectable Joomla magazine, but your readers definitelly expect more info on this topic.
VOTES:0
avatar
Well I did not get a 50, but I did not see a massive speed increase. Maybe slight.
VOTES:0
avatar
About:
"System - cache" plugin should be last one in the list

Please look at my screenshot:


If I understand correctly the "System - cache" plugin on my screenshot should be on position 32 instead of 29 ?

Please confirm. (I know it is not active on the screenshot).
VOTES:0
avatar
Maybe some in-depth explanations for what each htaccess rule does would be nice too... Nice article thought
VOTES:0
avatar
Hello everybody,
We applied this technique to a website recently developed with Joomla!. This website was having serious performance problems… in a few words: when 20 simultaneous users were accessing the site it went beyond the server processing and goes down.

We were very concerned; after all it was our second Joomla! project and already start looking for some cms framework alternatives when I found this article last week.

The cache was turned off and in order to follow the instructions of Grigor I enabled the cache plugin and the cache settings in the site configuration.

We run some tests. Here are the charts results.

On Chart1 you can see the gain in pages per second, stabilizing at 21 pages per second with 35 concurrent users. (Before we apply the settings the server could not handle more than 30 users simultaneously.)

Chart 2 is the comparison of load time per page by the number of concurrent users.

Chart 3 is the most important for us since we are stuck with a weak server. Note that the escalation process is much smoother and even 35 simultaneous users does not extrapolate the server processing.

That’s it. I hope this report helps you guys to review this technique.
VOTES:0
avatar
I think the Global Cache option just tells what should be the default behaviour of a cache-supporting extensions. For example, an extension that implements caching may ignore the global setting and create/use cache anyways.
VOTES:0
avatar
same here,
pasting this htaccess leads to error500
VOTES:0
avatar
I tested this, but don't work. Internal server error...
VOTES:0
avatar
I agree with Stephen Brandon - this was an informative article, but I was scared to death to even try to use any of it because I don't know what the impacts of enabling system cache on my page will be. Will it cause my content to load properly, etc... I rely on slideshows and other such content modules that probably are negatively impacted by caching. Also, altering my .htaccess file in such a dramatic fashion leaves me leary.

Just some comments from someone who knows just enough about Joomla to get myself in trouble...
VOTES:1
avatar
Great tip. I tested my site speed without any modifications, then added some techniques from Fotis Evangelou and tested again, then appended the techniques in this article and tested again. I saw results specifically with javascript compression and much faster loading times below 128K.
Used this site to text

Great information and a reminder to code sites better
VOTES:0
avatar
just remove this
(SetOutputFilter DEFLATE)
and the 500 server error will fix.

It helps me with yslow from score 71 to 79.

Thanks for the fileetag and expire header.
VOTES:0
avatar
Robert Österlind Friday, 11 March 2011
Works like a charm!
For those who has problem with server errors, try commenting out (as stated in the code):

Options +FollowSymLinks -Indexes
VOTES:0
avatar
Interesting Article but like others have said, requires a little more information then what is said here.

Would love to implement this concept with a bit more information.
VOTES:0
avatar
All lines after
SetOutputFilter DEFLATE
cause Apache 500 error.

but other lines with turning on cache plugin increase site speed
VOTES:0
avatar
Invalid command 'ExpiresActive', perhaps misspelled or defined by a module not included in the server configuration
VOTES:0
avatar
for those who gets server error message enable mod_deflate with extension c in you apache server.
VOTES:0
avatar
That will only improve off-site caching i.e after they have first visited the site.

If you want to really get things moving.... then you need this
[url=]sourceforge.net/projects/miser/[/url]
VOTES:1
avatar
tried everything, all your advices (except for the apache server commands coz i don't know how to do that), tried removing this or that line, but i keep getting the error 500 message...any tip to make it work?
VOTES:0
avatar
hi from Russia, this is work type of htaccess

### @version $Id: htaccess.txt 10492 2008-07-02 06:38:28Z ircmaxell $
# @package Joomla
# @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
# @license www.gnu.org/copyleft/gpl.html GNU/GPL
# Joomla! is Free Software
##

## Can be commented out if causes errors, see notes above.
Options +FollowSymLinks -Indexes

#
# mod_rewrite in use

DirectoryIndex index.php
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^(/component/option,com) [NC,OR]
RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|/[^.]*)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php

########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a tag in URL
RewriteCond %{QUERY_STRING} (\|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
#
########## End - Rewrite rules to block out some common exploits

# RewriteBase /

########## Begin - Joomla! core SEF Section
#

RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

#
########## End - Joomla! core SEF Section
Header set Expires "max-age=29030400, public"
Header unset ETag
FileETag None

ExpiresActive On
ExpiresDefault A600
ExpiresByType image/x-icon A2592000
ExpiresByType application/x-javascript A604800
ExpiresByType text/css A604800
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType text/plain A1200
ExpiresByType application/x-shockwave-flash A2592000
ExpiresByType video/x-flv A2592000
ExpiresByType application/pdf A2592000
ExpiresByType text/html A600
VOTES:0
avatar
Progresiv Dizajn Sunday, 26 June 2011
Thank You!! I tested this, work for 3 site.
VOTES:0
avatar
Thank you that was a brilliant suggestion, I got from 82/100 to 91/100 from this move. Thanks Ashley
Joomla 1.5.23, Yoothemes Template, Apache
VOTES:0
avatar
Thanks for the trick
VOTES:0
avatar
nice. Thanks a lot
VOTES:0
avatar
I get a 500 error each time I try to implement the .htaccess file change.
VOTES:0
avatar
I just change the plugin order and speeded up my page veeeeeeery, thanks very much
VOTES:0
avatar
Google's Page Speed showed my site at 60 out of 100. After following the directions here to the 'T' I ran page speed again. It showed me 60 out of 100.

Unless I have missed something.. uh.. dude.. wtf?!?
VOTES:0
avatar
awwwwwwwwwwww....this is awesome...my site speed changed after i added the script. And i suggest this is working fine.

Thanks
VOTES:0
avatar
Thanks a lot! works perfectly!
Before: Page Speed Score: 74/100
Afeter: Page Speed Score: 82/100
VOTES:0
avatar
does this work for joomla 2.5? when i am enabling rewrite engine.....only my home page is opening, for all other pages 'page not found' error occurring.
VOTES:0
avatar
Thank you so much. I was reluctant to try it on my busy website that has nearly 6,000 news articles. However I took the risk. Before applying the trick, my website had a Google Page Speed rank of 66/100. Now it has 76/100. Thank you so much.
VOTES:0
avatar
Does this code works for joomla 2.5 also??
VOTES:2
avatar
Dear Grigor

Many thanks for your article - helped speed up my site significantly from 0-11 to 75-81 on Google PageSpeed. Saved me a lot of time and headaches since I am very new to all of this. Max
VOTES:1
avatar
This is amazing. You're a star.
VOTES:0

Language Switcher