Website Speed Optimization: Why Your Django Site Loads Slow
Need help with custom web development? I provide custom web development for businesses ready to grow. Learn about my custom web development service or get in touch for a free consultation.
- Website Speed Optimization: Why Your Django Site Loads Slow
- Culprit #2: Static Files Served Like It's 2011
- Culprit #3: No Caching Strategy At All
- Where I'd Start If This Were Your Site
Website Speed Optimization: Why Your Django Site Loads Slow
I'm Ruslan Danelian, a web developer and Google Ads specialist who spends most of his week building and fixing websites for US service businesses — HVAC companies in Phoenix, plumbing outfits in Dallas, law firms in Chicago. And I can tell you the single most expensive sentence I hear on discovery calls: "The site works fine, it's just a little slow."
A "little slow" is rarely little. When I run paid search for a home services client, every extra second of load time quietly taxes the ad budget. Google's own research has shown that as page load time goes from one second to three seconds, the probability of a mobile visitor bouncing jumps by roughly 32%. If you're paying $45 a click for "emergency AC repair near me," you are literally buying bounces.
Django is a fantastic framework. It's also very easy to build a slow Django site without noticing, because everything looks fast on your laptop with three test records in the database. Here are the three culprits I find in almost every audit, and what I actually do about them.
Culprit #1: The N+1 Query Problem
This is the big one. In my experience, roughly seven out of ten slow Django sites I inherit have an N+1 problem hiding in plain sight on their highest-traffic page.
What it actually looks like
Say you run a roofing company site with a project gallery. Each project belongs to a service category and has a lead technician attached. Your view grabs fifty projects, and your template loops through them printing the category name and the technician's name.
Django dutifully runs one query to fetch the fifty projects. Then, for each row, it runs another query to fetch the category. Then another to fetch the technician. That's 101 database queries to render one page. On a local SQLite file, that might take 40 milliseconds and feel instant. On a production Postgres instance sitting in a different availability zone, with 4ms of network latency per round trip, you've just added 400ms of pure waiting before a single byte of HTML exists.
Now scale it. A service-area page listing 200 cities, each pulling its own reviews and its own pricing record? You're at 600+ queries and a two-second server response time. I've seen a legal intake directory hit 1,800 queries on one page load. The client thought they needed a bigger server. They needed two lines of code.
The fix
- select_related for foreign keys and one-to-one relationships. It performs a SQL JOIN and pulls the related object in the same query. Perfect for project → category or project → technician.
- prefetch_related for many-to-many and reverse foreign keys. It runs a second query and stitches the results together in Python. Use it for project → photos or city → reviews.
- only() and defer() when your model carries a giant text field you never display on the list page. No reason to ship 40KB of blog body per card.
- annotate with Count/Sum instead of calling .count() inside a loop. Let the database do the math once.
Install Django Debug Toolbar in development and Django Silk or a query-count middleware in staging. Make the number visible. On one plumbing client's site, converting four list views to proper prefetching dropped the homepage from 312 queries to 19, and Time to First Byte went from 1.9 seconds to 210 milliseconds. Same server. Same hosting bill.
When I run paid search for a home services client, every extra second of load time quietly taxes the ad budget.
Culprit #2: Static Files Served Like It's 2011
The second thing I check is how static assets get to the browser. Django's development server serving static files is fine locally and unacceptable in production — yet I still find it live on real business sites.
The usual offenders
- No compression or bundling. Fourteen separate CSS files and nine JS files means twenty-three HTTP requests before the page paints. Even with HTTP/2, that's overhead you don't need.
- Unoptimized images. This is the killer for service businesses. Someone uploads a 4.2MB photo straight from their iPhone as the hero image on the truck-wrap page. Multiply by six gallery photos and your "fast" page weighs 18MB.
- No far-future cache headers. Without Cache-Control set properly, returning visitors re-download your entire stylesheet on every page view.
- Render-blocking third-party scripts. Chat widgets, review badges, call-tracking scripts, heatmap tools — all loaded synchronously in the head.
What I do instead
My standard stack for a service-business Django site: WhiteNoise for compressed, hashed static files with immutable cache headers, or S3 plus CloudFront when there's meaningful media volume. Hashed filenames mean I can set a one-year cache lifetime safely, because a changed file gets a new URL automatically.
For images, I convert to WebP with a JPEG fallback, generate responsive sizes with something like django-imagekit or easy-thumbnails, and add loading="lazy" below the fold. That 4.2MB hero becomes a 180KB WebP at the correct display dimensions. On a recent HVAC rebuild, total page weight fell from 9.4MB to 780KB and Largest Contentful Paint improved from 6.1 seconds to 1.4 seconds on a mid-range Android over 4G.
And I move every non-essential third-party script to defer or load it after user interaction. The chat bubble does not need to exist before the phone number renders.
The second thing I check is how static assets get to the browser.
Culprit #3: No Caching Strategy At All
Here's the uncomfortable truth about most small-business Django sites: the content barely changes. Your service pages, your about page, your city landing pages — they're identical for every anonymous visitor, and they change maybe twice a month. Yet the default behavior is to regenerate them from scratch, query by query, on every single request.
Layer your caching
- Per-view caching for anonymous traffic on marketing pages. Fifteen minutes to an hour is usually plenty. A homeowner searching for water heater installation does not need real-time data.
- Template fragment caching for expensive components — a review carousel, a service-area map, a footer with dynamic locations — while leaving personalized bits uncached.
- Low-level cache API for computed values: aggregate rating scores, counts, external API responses. If you're calling a third-party review API on every page load, you're outsourcing your performance to someone else's uptime.
- Redis or Memcached, not the database cache backend. Using your database to store cache entries defeats the purpose. I've genuinely found this in production.
One caution from experience: never blanket-cache authenticated views. I audited a scheduling app where a naive per-site cache middleware served one customer's appointment details to another. Cache anonymous marketing pages aggressively; cache logged-in dashboards surgically, keyed by user ID, with short TTLs.
Invalidate deliberately
Cache invalidation is where people get burned. My rule: tie invalidation to the model save. When a client edits a service page in the admin, a post_save signal clears the relevant cache keys. No stale content, no manual "clear the cache" ritual, no support ticket at 9pm on a Saturday.
Want expert help with this? Let's make it happen.
Get a Free ConsultationWhy This Matters More If You're Buying Traffic
This is where my two hats overlap. As a developer I care about TTFB and LCP. As someone managing Google Ads budgets, I care about cost per lead — and those numbers are connected.
Slow landing pages hurt you three ways. Visitors abandon before the form loads. Core Web Vitals feed into your landing page experience, which influences Quality Score and therefore your cost per click. And mobile users on job sites with weak signal — exactly the audience for emergency plumbing or towing — are the least tolerant of heavy pages.
On one campaign, after we cut landing page load time from 4.8 seconds to 1.6 seconds, conversion rate rose from 2.1% to 3.4% on essentially unchanged traffic. Same ads, same keywords, same budget. Cost per lead dropped by roughly a third. That's not a development win, that's a business win.
Where I'd Start If This Were Your Site
- Run PageSpeed Insights on your top three landing pages, not just the homepage. Test mobile.
- Install Debug Toolbar and count queries on those same pages. Anything over 30 deserves a look.
- Check total page weight in DevTools. If it's over 2MB, your images are the problem.
- Add per-view caching to anonymous marketing pages today. It's the cheapest win available.
- Re-measure after each change so you know what actually moved the needle.
Speed optimization isn't glamorous work, but it compounds. Fewer queries means a smaller server bill. Lighter pages means better ad economics. Faster load means more of the traffic you already paid for actually reaches your contact form.
If your Django site feels sluggish and you're not sure whether it's the code, the hosting, or the twelve tracking scripts someone added last year — that's exactly the kind of audit I do. Let's find out what's actually slowing you down, fix it in order of impact, and stop paying for visitors who never see your page.
Related reading: Building Real-Time Dashboards with Django Channels and HTMX · The Complete Guide to Multi-Tenant Django Applications · Django Deployment: Gunicorn, Nginx, and Systemd on a VPS



Frequently Asked Questions
Why is my Django site slow?
The usual causes are unoptimised database queries, missing caching, large images and heavy JavaScript or CSS. Profiling the real pages shows which one matters most.
Does site speed affect Google rankings and ads?
Yes. Page experience is a ranking signal, and a faster landing page tends to convert more of the traffic you pay for, which can lower your effective cost per lead.
What is a good page load time?
Aim to meet Google's Core Web Vitals thresholds on mobile. Those measure loading, interactivity and visual stability, and give clearer targets than a single load time number.
What should I fix first?
Start with the biggest wins: compress and properly size images, add caching and fix slow queries. Measure before and after each change.
Full-stack developer specializing in Django, AI automation, and Google Ads management. Building production SaaS platforms and custom web applications for businesses across the US.