Course contentsShow
← Web Development
Lesson 2928 of 2,98252. Frontend SecurityFree lesson

Mixed Content: Blocking and Warnings

Learn how browsers handle mixed content when HTTPS pages load HTTP resources and how to fix it.

Mixed Content: Blocking and Warnings

You'll learn how browsers protect users when HTTPS pages try to load HTTP resources, and how to identify and resolve mixed content issues.

What is Mixed Content?

Mixed content occurs when your HTTPS page attempts to load resources (images, scripts, stylesheets, iframes, etc.) over insecure HTTP. Browsers treat this as a security vulnerability because an attacker could intercept the HTTP request and modify the resource, undermining the security HTTPS provides.

Think of it like living in a gated community (HTTPS) but leaving your front door wide open (HTTP resources). The perimeter security becomes meaningless if there's an easy entry point.

How Browsers Handle Mixed Content

Browsers classify mixed content into two categories:

Active Mixed Content (scripts, stylesheets, iframes, XHR/fetch requests) is blocked automatically. These resources can execute code or modify page behavior, making them dangerous. You'll see console errors like "Mixed Content: The page was loaded over HTTPS, but requested an insecure resource."

Passive Mixed Content (images, audio, video) traditionally triggered warnings rather than blocks, since they can't execute code. However, modern browsers increasingly block these too.

Fixing Mixed Content

  1. Use protocol-relative URLs: Change http://example.com/script.js to //example.com/script.js (inherits the page's protocol)
  2. Use HTTPS URLs explicitly: Update all resource URLs to https://
  3. Use the upgrade-insecure-requests CSP directive: Automatically upgrades HTTP requests to HTTPS (as you've learned previously)

Check browser DevTools' Console and Security tab to identify mixed content issues. The Security tab shows a detailed breakdown of which resources triggered warnings or blocks.

Key Takeaway: Mixed content undermines HTTPS security; modern browsers block dangerous HTTP resources on HTTPS pages, so always serve all resources over HTTPS or use upgrade-insecure-requests to automatically upgrade them.