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