Make Drupal Faster: Performance Optimization
A fast Drupal website leads to a better user experience, higher conversions, and better rankings in Google. In this guide, we cover all the ways to optimize your Drupal site for maximum speed.
Why Performance is Important
Speed has a direct impact on your website:
- User Experience: Visitors leave slow sites
- SEO Rankings: Google rewards fast websites
- Conversions: Every second of delay costs revenue
- Server Costs: Efficient sites use fewer resources
Studies show that 40% of visitors leave a page that takes longer than 3 seconds to load.
Configuring Drupal Caching
Caching is the most important optimization you can do.
Enabling Internal Page Cache
Drupal has powerful built-in caching:
- Go to Configuration and then Development
- Click on Performance
- Configure Browser and proxy cache:
- Page cache maximum age: Minimum 1 hour, preferably 1 day
- Click on Save configuration
Setting Cache per Content Type
For dynamic content, you can fine-tune caching:
- Go to Structure and then Content types
- Edit the content type
- Under Publishing options, adjust cache settings
- Save the changes
Clearing Cache
After changes, you may need to clear the cache:
- Go to Configuration and then Performance
- Click on Clear all caches
Via Drush (SSH):
drush cache:rebuild
# Or simply:
drush cr
CSS and JavaScript Aggregation
Aggregation combines files for faster load times.
Enabling Aggregation
- Go to Configuration and then Development
- Click on Performance
- Under Bandwidth optimization:
- Check Aggregate CSS files
- Check Aggregate JavaScript files
- Click on Save configuration
Benefits of Aggregation
- Fewer HTTP requests
- Smaller file size due to compression
- Faster initial load time
After Adjustments
If you modify CSS or JS, clear the cache to refresh the aggregated files.
Database Optimization
An optimized database is essential for performance.
Run Cron Regularly
Drupal cron cleans up the database:
- Go to Configuration and then System
- Click on Cron
- Set the frequency (at least every 3 hours)
- Or run manually: click Run cron
Via crontab (recommended):
# Run cron every 6 hours
0 */6* * * cd /path/to/drupal && drush cron
Optimizing Database Tables
Via phpMyAdmin:
- Open phpMyAdmin in DirectAdmin
- Select your Drupal database
- Select all tables
- Choose Optimize table in the dropdown menu
Cleaning Cache Tables
Drupal stores a lot of cache in the database:
# Via Drush
drush sql-query "TRUNCATE cache_default"
drush sql-query "TRUNCATE cache_render"
drush sql-query "TRUNCATE cache_page"
PHP Optimization
Optimize PHP for better Drupal performance.
Activating OPcache
OPcache significantly speeds up PHP:
- Check if OPcache is active via Reports and then Status report
- Or via phpinfo()
- At Theory7 hosting, OPcache is enabled by default
Increasing PHP Memory
For complex sites:
- Go to DirectAdmin
- Click on Domain Setup and then PHP Settings
- Increase memory_limit to 256M or 512M
- Save the changes
PHP Version
Always use the latest PHP version:
- PHP 8.2 or 8.3 recommended for Drupal 10
- Newer versions are significantly faster
Module Optimization
Modules can greatly affect performance.
Disabling Unnecessary Modules
Every active module consumes resources:
- Go to Extend
- Review all active modules
- Disable unused modules
- Remove them completely if possible
Installing Performance Modules
Consider performance modules:
- BigPipe (core):
- Loads pages progressively
- Included by default in Drupal 10
- Advanced CSS/JS Aggregation:
composer require drupal/advagg- Advanced optimization of assets
- Bundling and minification
Identifying Slow Queries
Via database logs or modules:
- Activate slow query log in MySQL
- Analyze the slow queries
- Add indexes where necessary
Views and Content Optimization
Views can be slow if not configured properly.
Enabling Views Caching
- Edit the View
- Go to Advanced settings
- Click on Caching
- Set time-based caching
- Save the View
Using Pagination
Limit the number of items per page:
- In the View, go to Pager
- Set a reasonable number of items (10-25)
- This prevents heavy database queries
Limiting Content Preloading
Load only the fields you need:
- Use Fields instead of Content display
- Select only the necessary fields
- Avoid complex relationships
Optimizing Images
Images are often the largest files.
Using Image Styles
- Go to Configuration and then Media
- Click on Image styles
- Create styles for different formats
- Drupal automatically scales images
Activating Lazy Loading
Load images only when they come into view:
- Drupal 10 has basic lazy loading built-in
- Consider modules like Lazy-load for more control
WebP Format
Use WebP for smaller files:
- Check if your server supports WebP
- Use Image Styles to generate WebP
- Modern browsers display WebP, older ones get a fallback
Performance Monitoring
Regularly measure your results.
Internal Tools
- Go to Reports and then Status report
- Check performance metrics
- View database and cache status
External Tools
- Google PageSpeed Insights: Comprehensive analysis
- GTmetrix: Load times and waterfalls
- WebPageTest: Detailed metrics
Performance Checklist
- Page cache active
- CSS/JS aggregation on
- Cron runs regularly
- OPcache active
- Images optimized
- Unnecessary modules disabled
Related Articles
- Drupal Basic Configuration
- Installing Drupal via Installatron
- Drupal Backup and Migration
- More information about Drupal hosting at Theory7
Need Help?
We are here for you! Are you facing any issues or do you have questions? Our support team is happy to assist you personally. Send us a message via the ticket system - we usually respond within a few hours and are happy to help.
0 van 0 vonden dit nuttig