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

HTTP 301 Page moved in Drupal

Scope: Move an old document to a new URL with HTTP 301 Permanent Redirect.

Module used (required if you don’t want to modify an existing page): URL aliases.

  1. Create a new page (or edit an old one). Select “PHP code” in input type.
  2. Fill the url alias box, with the old document path
  3. Insert the following code: <?php
    // Permanent redirection
    header(“HTTP/1.1 301 Moved Permanently”);
    header(“Location: http://www.yoursite.tld/location&#8221;);
    exit();
    ?>
  4. Save.

Note: Obviously you can’t see the page (you’ll be redirected to specified address), but you can edit or delete the page from admin/content/node. As admin, if you try to unpublish the page you’ll be redirected anyway: you have to delete the page to fix it.

See also: http://www.somacon.com/p145.php