The Joomla! ® Community Magazine

Increase your site's speed dramatically

Written by Grigor Mihov | Tuesday, 01 March 2011 00:00 | Published in 2011 March
Level of Difficulty:Beginner 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:
  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 35192 times
Tagged under Administrators

Leave a comment

Make sure you enter the (*) required information where indicated.

[b] [i] [u] [s] [url] [quote] [code] [img]   

Comments (35)

  • avatar
    • 1
    • 2
    Stephen Brandon

    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?

  • avatar
    • 3
    • 0
    abang

    SetOutputFilter DEFLATE

    The line above is causing a page error 500.
    Any idea why?

  • avatar
    • 2
    • 0
    N. Kraakman

    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.

  • avatar
    • 1
    • 0
    Steph

    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!!

  • avatar
    • 1
    • 0
    Brian Ducharme

    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:

    Code:
    a2enmod headers
    Code:
    e2enmod expires

    You will then need to run:

    Code:
    /etc/init.d/apache2 reload
  • avatar
    • 0
    • 0
    Grigor Mihov

    @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.

  • avatar
    • 0
    • 0
    Mirko Mikan

    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.

  • avatar
    • 0
    • 0
    Anthony

    Well I did not get a 50, but I did not see a massive speed increase. Maybe slight.

  • avatar
    • 0
    • 0
    Sinterklaas

    About:
    "System - cache" plugin should be last one in the list

    Please look at my screenshot:
    View image

    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).

  • avatar
    • 0
    • 0
    aa

    Maybe some in-depth explanations for what each htaccess rule does would be nice too... Nice article thought

  • avatar
    • 0
    • 0
    Tiago Donatti

    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.

  • avatar
    • 0
    • 0
    Gerardo

    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.

  • avatar
    • 0
    • 0
    bagou

    same here,
    pasting this htaccess leads to error500

  • avatar
    • 0
    • 0
    Kunci

    I tested this, but don't work. Internal server error...

  • avatar
    • 1
    • 0
    Matt Payne

    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...

  • avatar
    • 0
    • 0
    Cindy Montano

    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

  • avatar
    • 0
    • 0
    wayne

    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.

  • avatar
    • 0
    • 0
    Robert Österlind

    Works like a charm!
    For those who has problem with server errors, try commenting out (as stated in the code):

    Options +FollowSymLinks -Indexes

  • avatar
    • 0
    • 0
    Rob

    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.

  • avatar
    • 0
    • 0
    Andy

    All lines after
    SetOutputFilter DEFLATE
    cause Apache 500 error.

    but other lines with turning on cache plugin increase site speed

  • avatar
    • 0
    • 0
    kristof

    Invalid command 'ExpiresActive', perhaps misspelled or defined by a module not included in the server configuration

  • avatar
    • 0
    • 0
    Remus

    for those who gets server error message enable mod_deflate with extension c in you apache server.

  • avatar
    • 0
    • 0
    bagou

    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?

  • avatar
    • 0
    • 0
    MaRt

    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 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

    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

  • avatar
    • 0
    • 0
    Progresiv Dizajn

    Thank You!! I tested this, work for 3 site.

  • avatar
    • 0
    • 0
    Ashley

    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

  • avatar
    • 0
    • 0
    admin

    Thanks for the trick

  • avatar
    • 0
    • 0
    toriun

    nice. Thanks a lot

  • avatar
    • 0
    • 0
    Todd Carpenter

    I get a 500 error each time I try to implement the .htaccess file change.

  • avatar
    • 0
    • 0
    Snjezna

    I just change the plugin order and speeded up my page veeeeeeery, thanks very much

  • avatar
    • 0
    • 0
    Bluebeep

    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?!?

  • avatar
    • 0
    • 0
    Fekade

    awwwwwwwwwwww....this is awesome...my site speed changed after i added the script. And i suggest this is working fine.

    Thanks

  • avatar
    • 0
    • 0
    Sergio Viator

    Thanks a lot! works perfectly!
    Before: Page Speed Score: 74/100
    Afeter: Page Speed Score: 82/100

  • avatar
    • 0
    • 0
    madhu

    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.

Language Switcher