Back to blog

Follow and Subscribe

Five ways to optimize your Drupal site

Neerav Mehta

Founder & CEO, Red Crackle

Drupal is a flexible, open source content management system (CMS). It powers more than a million websites, including http://www.weather.com, https://www.whitehouse.gov, and http://www.economist.com. Although Drupal allows you to create a site via an easy-to-use user interface, it can be slightly slow out of the box. You need to optimize it to ensure fast load times and good experiences for your users.

Why speed matters

Regular readers of the Fastly blog may be aware that page speed matters, but in case you have lingering doubts:

As you can see, it's in your best interest to make sure your site is fast. If you’re using Drupal, it’s even more essential that you optimize your site for speed, making sure your users can access your content quickly.

Five ways to speed up your Drupal site:

Optimize server infrastructure

  • Make sure your server has enough memory. If you find that swap space is being utilized, then increase the memory. If that's not possible, use a faster and more memory efficient web server such as nginx instead of Apache.

  • If you are using PHP 5.3 or below, use an opcode cache such as APC. PHP 5.4 and above comes with opcode cache so you don't need to worry about it.

  • Drupal stores all its cached data in the database. In general, database access is slow. Use memcache or redis to use memory instead of database for storing Drupal's cached data.

Compress content

Gzip all the data that is being returned by the web server. This includes HTML, CSS, JS, and images. Compressing the response ensures a lot less data is transferred from the server back to the browser, reducing page load time. Content can be compressed by Drupal itself or by a web server such as Apache or nginx.

Move JS and non-critical CSS to the footer

You may have heard that moving JS to the footer ensures the browser doesn't get blocked while loading JS. You should also do the same with non-critical CSS, such as CSS statements that don’t apply to the content that appears above the fold on a page. As a result, content above the fold gets rendered quickly and the rest of the CSS can load later.

Aggregate and minify CSS, JS, and images

In order to reduce overall page load time, you can make it so the browser will request a smaller number of files from the server. To do this, aggregate and minify:

  • CSS files into a small number of CSS files

  • JS files into a small number of JS files

  • Images into sprites — typically background images and icons can easily be combined into sprites.

These steps will help decrease the number of server requests, reducing the overall page load time.

Use a CDN

This may also be familiar to readers of the Fastly blog, but for those of you who need a reminder, a content delivery network (CDN) offers:

  • Faster load times for web and mobile users

  • Quick scalability during heavy traffic

  • Minimized risk of traffic spikes at point of origin, ensuring site stability

  • Decrease in infrastructure costs due to traffic offloading (less load on origin)

  • Better site performance

For more on how to optimize your Drupal site with Fastly (including detailed setup instructions), check out the corresponding blog on my website, Red Crackle, a Drupal development company.