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

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

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

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

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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: