Drupal is a highly scalable CMS and it’s always tempting to install more custom or contributed modules than you might need. Drupal 8 increased its core functionality by shipping with many commonly used modules including Views plus it has improved Block management.
There’s a lot you can build with Drupal right out of the box or with just a few other modules. Drupal themes and templates can also become bloated with unnecessary styles and scripts so it’s important to eliminate unwanted code or even install a theme that provides all of the essential framework you need to get started. A Bootstrap theme is a good example.
A few basic steps to improve loading times for a Drupal site:
- Enable page caching and CSS/JS aggregation in Performance settings.
- Uninstall any unused contributed modules or assess whether a module is needed at all.
- Avoid manually embedding scripts in the HTML header. Is there a module available?
- Use image fields and image styles to crop and optimise the source image.
- Avoid embedding social media widgets or iframe content.
Less code will correlate with a better user experience. In many cases a feature request by a client is likely solvable by being more creative with Drupal’s core tools. Be less tempted to install quick fix modules to solve a problem.
Basics for better optimisation
1. Getting mileage from Drupal core
A Drupal site can function well with only two or three content types and a few custom blocks or views. Seeing patterns and repeating elements in complex designs helps to plan the most efficient build. It’s the content itself (typography, imagery, calls to action) that often brings a website to life without the need for extra code or modules.
Entity fields in Drupal can be reused across many templates and content types. This also reduces class names and the amount of CSS you write. Utilise field collections for custom field groups such as calls to action — with perhaps a heading, image and link. Getting lots of mileage out of a very small pool of fields by keeping the field names generic e.g. “field_heading”.
2. Work with efficient themes and CSS libraries
Use leaner frameworks for Drupal themes or build from scratch. More advanced themes may also ship with a lot of additional code that will likely not be required for your design. You can end up with lots of features and settings that are rarely or never used which can impede editing.
CSS extensions such as LESS and SASS provide coding shortcuts that can save a lot of development time. However, the CSS file that is outputted via a compiler will be much bigger. So it’s a good idea to keep an eye on file size when applying reusable functions and variables.
3. Limiting third-party embeds and privacy issues
A common cause of slow loading websites is embedded third-party content such as social media widgets, tracking code or web fonts. Plan which content is essential to user experience on your site and wherever possible provide links to external content rather than embedding it. Exceptions might be video, web fonts or analytics code.
Check your privacy policy and GDPR guidelines. Many third-party widgets (e.g., YouTube videos), will add their own tracking codes too. By limiting the amount of external content you embed you reduce page waiting times and also gaining more trust from visitors.
4. Secure, reliable and robust web server
The choice of hosting provider makes a big difference to website performance. Security is the first priority and ensuring the server space is managed by a developer or IT professional. Configure regular automated tasks such as a cron run to clear caches and flag up website issues or bugs.
Resist the temptation to use your CMS website for file storage or file sharing. The purpose of a CMS is to manage websites pages and publishing.
Improved user engagement and trust
Leaner code improves the website’s performance and also provides a better user experience and gains trust from visitors. Your website is also easier to maintain and it’s less painful when performing major Drupal upgrades or migrating content.