← Back to Blog
Django May 27, 2026 1 min read 3 views

Django Performance: 10 Tricks That Cut My Page Load by 70%

# Django Performance: 10 Tricks That Cut My Page Load by 70% A client came to me with a Django app that took 4.2 seconds to load the homepage. After two days of profiling and optimisation, it loaded in 1.1 seconds. Here's what I did. ## 1. select_related and prefetch_related The single biggest win. Use `select_related` for FK/O2O, `prefetch_related` for M2M. ```python # Before: 47 queries posts = BlogPost.objects.all() # After: 2 queries posts = BlogPost.objects.select_related('author', 'category').prefetch_related('tags') ``` ## 2. Database Indexes Add indexes to fields you filter or order by frequently. ```python class BlogPost(models.Model): class Meta: indexes = [ models.Index(fields=['status', 'published_at']), models.Index(fields=['-created_at']), ] ``` ## 3. Redis Caching for Heavy Queries ```python from django.core.cache import cache def get_featured_posts(): posts = cache.get('featured_posts') if not posts: posts = list(BlogPost.objects.filter(is_featured=True).select_related('category')[:5]) cache.set('featured_posts', posts, timeout=300) return posts ``` ## Results | Metric | Before | After | |--------|--------|-------| | Page load | 4.2s | 1.1s | | DB queries | 47 | 3 | | Memory usage | 280MB | 95MB |

Related Articles

📖
Celery + Django: The Complete Setup Guide for 2024

Have a project in mind?

Let's build something together.

💬 Get In Touch