Drupal is a leading CMS that is being used to design various government, public and private websites. When it comes to business, many organizations prefer Drupal for its high scalability, security and performance. However, to maintain the standard of your Drupal site and offer your visitors a satisfying experience you have to optimize the performance of your site. Here is a list of to-dos to get you going:
1. Core Caching & Aggregation: Drupal 8 Core provides two modules for caching - Internal Dynamic Page Cache and Internal Page Cache.
- Once you activate the two modules, on one hand, the Internal Dynamic Page Cache automatically caches dynamic content for any user to maintain both cache correctness and hit ratio. At the other, the Internal Page Cache module caches pages for anonymous users in the database. The caching is done when a server receives a request for the first time. It helps in quickly serving the cached version for all later requests and allows your browser to render a page faster.
- CSS & JS Aggregation: If JS & CSS aggregation is off, multiple JS & CSS files get created, resulting in the equal number of HTTP requests. As the result, the page load time increases. To reduce the page load time by reducing the number of JS & CSS files, you need to enable this setting from Configuration -> Development -> Performance.
To effectively cache your pages, you can use contributed modules like Memcache to keep standard cache and database separated, Varnish Purge to reduce load on web server and Redis for better storage and retrieval.
2. Compress Images: When it comes to images, make sure you use the compressed files. By default Drupal 8 compresses your images by 75%. If you wish, you can change the setting at Development -> Image Toolkit. But remember, higher the number, bigger the file size will be.
3. Disable some Core and unused modules: Disable all modules that are not required. For instance, if you have Dev instance, disable Update Manager on Production site. Update Manager regularly pings drupal.org to check if any new version is available. Burdening your production site with a module that regularly scavenges your bandwidth is not a good idea. Another bandwidth consuming module on a production site is the Database Logging module. It logs every notice or error on a database, you don’t need something as such on your production site. In addition, disable modules like Devel and Kint which are not required on your site.
4. MySQL Table Optimization: Set up the DB Maintenance Module as a part of the regular cron job. Meant for optimization of administrator-selected tables, use the OPTIMIZE TABLE function to practically defragment your table. For MyISAM tables, use OPTIMIZE TABLE to repair a table, sort the indexes, and update table statistics. For BDB and InnoDB, the OPTIMIZE function rebuilds the table. What you need to keep in mind that when OPTIMIZE TABLE runs MySQL locks the tables.
5. Query Optimization: Use Devel module to check slow query logs. You can see queries that take more time and target to optimize those. Enable MySQL query caching variable i.e. query_cache_size to cache query.
6. PHP Profiling: XHProf, a hierarchical profiler for PHP, uses a simple HTML based user interface to view and share profiler results easily. Due to its hierarchical nature, it becomes easy to determine which chain of calls has led to a particular function. The callgraph image support allows for a super comprehensible report on inclusive and exclusive metrics such as wall (elapsed) time, CPU time and memory usage and of course call counts.
7. Enable Fast 404 Module: Broken images or CSS file paths make page speeds significantly sluggish. But Drupal still attempt to load these paths and return a 404 error. Drupal does a full bootstrap when serving a 404, and in the process consumes a lot of resources. The Fast 404 module prevents this slowdown and quickly delivers the 404 error messages.
8. Using Content Distribution Network (CDN): CDNs have data centers in every region of every continent. In case Drupal doesn’t need to recreate the HTML, the content is served from a CDN to reduce the load times. A few of the CDN service providers worth mentioning are Cloudfare, Akamai, and Amazon.
9. Using MariaDB instead of MySQL: MariaDB turns data into structured information in various web applications. Besides offering a better storage engine, MariaDB supports TokuDB that handles big data for large organizations and corporate users. Note that in MariaDB, Aria and XtraDB have replaced MySQL's MyISAM and InnoDB. Aria offers better caching, a benefit particularly perceived during disk-intensive operations. Moreover, temporary tables also use Aria to speed up complex queries. In parallel, Percona's XtraDB gets rid of all of the InnoDB problems with slow performance and stability, especially in high load environments.
10. Nginx vs Apache: Preferring Nginx over Apache is a good choice as Nginx has faster response time compared to Apache.
11. Managing Servers: Google Pagespeed and Yahoo YSlow are two excellent tools to keep track of page download time. Their reports come with suggestive corrective actions. As a preventive method to keep page speed under control, make the changes as listed below:
- Keep DNS lookup - OFF
- Set FollowSymLinks everywhere
- Never set SymLinksIfOwnerMatch
- Avoid content negotiation
- Use type-map files rather than Options MultiViews directive
- Set KeepAlive to on and KeepAliveTimeout to as low as 1 or 2 seconds
- Disable or comment access.log settings
- Enable mod_deflate or mod_gzip
- Install APC server with higher memory limit apc.shm_size = 64
In addition to the list, we suggest using a scalable server as that will absorb the sudden spike in traffic or load. It’s even more important if yours is a high traffic website. Otherwise, you may settle with dedicated or shared server hosting.
12. Accelerated Mobile Pages (AMP): If your website is mobile friendly, use AMP to enhance its performance. Before you take guard, get this point clear, AMP is not a replacement for your entire site. It simply delivers articles and other content-focused pages at a blazing fast pace to site visitors on a mobile. To make your site AMP compatible, use AMP field formatters and manage the conversion of your site content so they use the proper AMP tags. If you use the Token module, after filtering and replacing the tokens, the AMP PHP library will replace the raw HTML content with AMP HTML components and offer a flawless rendition of your site on a mobile browser. This is particularly helpful in validating the wide variety of embedded content under the editorial control.
During a time when the average expected page load time is less than three seconds, you cannot risk your site performance. Not even by citing security as the reason. Security is expected, by default. To keep your site secured and offer a high performance you need to optimize your site. Use the suggested steps to strike balance between the two. Once you do that, you know you can return home with visitors converted to customers and customers converted to promoters who team up all together to keep in the black.