In this article I’ll show you some things I did to optimize the performance for my Drupal 7 website on a Bluehost-powered shared hosting solution. I explored this issue pretty deeply so I’m going to cover much of what you can do to optimize your site. There are some things I won’t cover (such as APC, memcached, and Varnish) which a shared hosting solution won’t allow. However, if you have your own server, by all means implement those solutions as well!
Benchmarking
First, It’s useful to benchmark where you are in terms of site performance. In the unlikely event you don’t need to do any optimizations, there’s no need to waste your time right? So, first check out what you’ve got. Here are the sites I used (yes, I used them all). Each one gives some different information that’s valuable:
- GTMetrix: http://gtmetrix.com/
- Google PageSpeed: https://developers.google.com/speed/pagespeed/insights/
- WebPageTest: http://www.webpagetest.org/
- Pingdom: http://tools.pingdom.com/fpt/
- Bytecheck: http://www.bytecheck.com/
Testing Strategy
Now, I recommend the following test. As you implement each of the solutions outlined below, clear your site cache, and then test your URL at each of the sites listed above. It will be helpful to have them all open in separate tabs in your browser while you work on this.
Solutions
Optimization #1: Optimize your Images
The importance of this optimization can’t be overstated. Images take up a lot of bandwidth, so compress them. There are several online tools you can use to compress your files. Images should be resized correctly as well. I found ‘Shrink O’ Matic’ very useful:
http://toki-woki.net/p/Shrink-O-Matic/
Optimization #2: Improve your PHP Performance
On Bluehost this is easy to do, just search for ‘PHP Config’ and enable PHP 5.4 (FastCGI). If you’re using another host you may have to ask your provider to upgrade this for you.
Optimization #3: Add Indexes to your MySQL Tables
If your site routinely does a lot of queries you’ll want to add indexes to your most frequently queried tables. To find which tables and fields are being queried the most, enable the ‘Devel’ module. Then go to Configuration > Devel Settings and check ‘Display query log’. Every page of your site will now show the queries that generate the page. You’ll also see how long each query takes. Bravo! Now open your MySQL database and add indexes to your tables, like so:https://stackoverflow.com/questions/3002605/how-to-add-indexes-to-mysql-tables.
Optimization #4: Add the ‘Boost‘ module
Follow the directions here: https://www.drupal.org/node/1459690.
Optimization #5: Use the Views Mini Pager and Cache your Views
This one assumes you’re using of Views of course. If you are, and you return multiple pages of results and use a pager, then you’ll really save bandwidth by using the mini pager rather than the full pager. There’s also a module you can use called ‘LitePager’ but I found it didn’t improve my site’s performance any more than the default ‘mini’ pager. I always err on the side of not installing modules I don’t have to install, so I just used the mini pager.
Also makes sure to turn on caching for your Views (in the Views ‘Advanced’ tab).
Optimization #6: Remove unused junk and Update
In the same vein as #5, remove or at least disable, any modules you aren’t actively using on your site. Also, make sure your site is updated with the most recent code for all contributed modules and core.
Optimization #7: Install Cache Expiration Module
Follow these directions to enable it with Boost: https://www.drupal.org/node/2158615.
Optimization #8: Make your Google fonts Local
Instead of using the @import method or even the preferred <link> method in your html.tpl.php file, download the font files manually using this site. Install those in a folder called ‘fonts’ in your theme, and then use the CSS code generated from that same page and put that in your site’s CSS file. Make sure to change the links to the font files to where it can be found ‘relatively’ from your css file.
Optimization #9: Install and Configure Advagg
This module will compress your JavaScript and CSS Files and put them at the bottom of your pages (rather than in the header where they try and load before your HTML, slowing down user experience). This post has some good recommendations for using Advagg purposely: http://drupal.stackexchange.com/questions/107311/eliminate-render-blocking-javascript-and-css-in-above-the-fold-content.
Optimization #10: Disable the ‘Update Manager’ module
You’ll need to turn this on again every time you want to add a new module using the UI, but it improves performance to disabled it.
Optimization #11: Replace Default Cron with Elysia Cron
Elysia Cron replaces the default Cron and gives you more control over when and how often Cron runs on your site.
Optimization #12: Change Settings for Google Analytics
If you’re using Google Analytics module make sure to configure the module’s advanced settings and select ‘Locally cache tracking code file’.
Optimization #13: Add a CDN
When using Bluehost this is easy enough. They provide a solution called ‘Cloudflare’. You can find it by going to your cpanel and searching for it. Make sure to first activate it, and then ‘edit’ it to enable it for your domain. This whole process can take up to 24 hours to fully enable. Once it does you’ll see a checkmark in a green box on the WebPageTest site when you test your site.