Improve Drupal performance

I use YSlow to check a Drupal site performance. Here some tips to get an A with Drupal 5.x.

Step 1: Fewer HTTP requests:

  • Aggregate CSS (/admin/settings/performance)
  • Aggregate JS with Javascript Aggregator (experimental). To avoid JavaScript errors in some modules (i.e. TinyMCE), you can use the dirscard list patch by derjochenmeyer on the dev version (it’ll be added to the next release). To Drupal 6.x users: Drupal 6.x comes with a native JS Aggregator support, so you don’t need an additional module.
  • Reduce CSS background images: select carefully your theme.

Step 2: Compress pages on-the-fly:
Many modern browsers support Gzip compression. Through .htaccess, you can tell your server to serve gzipped HTML pages, JavaScript and CSS files (or any other text file, since images like JPG and PNG are compressed natively). You can use two approach, depending on your server settings, just add on bottom of your .htaccess:

  1. PHP flag method (compress only php served pages):
    # via-PHP compression (only with compatible browsers)
    php_flag zlib.output_compression On
  2. Apache mod_deflate method (preferred method where available)
    # Enable file compression by MIME type
    AddOutputFilterByType DEFLATE text/html text/plain text/xml
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE text/css
    # Exclude Not compatible browsers (uncomment to activate)
    # BrowserMatch ^Mozilla/4 gzip-only-text/html
    # BrowserMatch ^Mozilla/4\.0[678] no-gzip
    # BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

    Using this method, you can compress HTML pages, JavaScript, CSS files specifying ;MIME type

See also / references

10 Responses to “Improve Drupal performance”


  1. 1 Nguyen July 12, 2008 at 4:04 pm

    Thank you very much, I have just applied at my website.

    Data Savings: 75.86%

  2. 2 james September 10, 2008 at 6:23 pm

    good article man.
    keep it up.

  3. 3 Gold September 23, 2008 at 11:35 am

    Thanks for your advice! It helps me a lot!
    And what about improving performance of the admin pages?
    It is a most important thing for me now.

  4. 4 chirale September 26, 2008 at 3:25 pm

    Hi Gold, on Drupal 6.x in many cases disabling “Update status” and all “Developement” (e.g. Dev, Coder, etc.) modules on a production website could improve performances for an administrator user. Remember that page caching systems are effective only on anonymous users’ browsing.

    Memory consumption is another hot topic for performance boost: on Drupal memory consumption: some tips you can read more about that. Thanks for visiting and Happy drupalling!

  5. 5 Web 2.0 Drupal Solutions November 2, 2008 at 10:39 pm

    Excellent job! Many thanks!

    Keep it up!

  6. 6 Mikhailov Anatoly December 17, 2008 at 4:09 am

    How often do you think about improving performance of Apache2 httpd web-server?
    “It’s too slow”, “we need more powerfull server”, etc.
    Telling the truth, default settings of Apache2 aren’t good and it’s best to try optimizing those first, before thinking of more advanced solutions.

    Mod_deflate in apache2 is pretty much the same as mod_gzip in apache1.3, and mod_deflate is included with the apache2 source package. Both modules allow compressing of the apache server on the fly

    http://railsgeek.com/2008/12/16/apache2-httpd-improving-performance-mod_deflate-gzip

  7. 7 chirale December 17, 2008 at 7:38 pm

    Thanks Mikhailov: I know that lower compression are used primarily to reduce CPU workload. Since Drupal has his own Javascript and CSS cache system, aggregating many files into a single one, an interesting system is to gzip that file only one time, redirecting request to this instead recompressing it at any request.

    Here some howto (drupal 5.x and 6.x):
    http://drupal.org/node/249211
    http://drupal.org/node/249211#comment-900656
    http://kaioa.com/node/78

  8. 8 DJpumpkin March 6, 2009 at 2:13 pm

    I tried your suggestion 2. Apache mod_deflate method (preferred method where available)

    Now I get hundreds of lines of errors like this in my apache error log:
    [Fri Mar 06 14:03:04 2009] [error] an unknown filter was not added: DEFLATE

    Any ideas?

  9. 9 Brian May 15, 2009 at 8:50 pm

    Thank you very much this is wonderfully helpful. I went from a D to a B in Y-Slow- hah


  1. 1 PHP Coding School » Blog Archive » php tips [2008-02-06 22:42:00] Trackback on February 6, 2008 at 10:54 pm

Leave a Reply




IE6: Rust in Peace

Blog Stats

  • 102,275 hits
My Bookshelf

Texts double licensed under Creative Commons Attribution - Share Alike license and GNU Free Documentation License. Examples may contain software licensed under GNU General Public License. Images and comments texts aren't necessarily licensed under these terms.