Firefox Resource Tailing Documentation

Overview

Resource tailing is a network optimization mechanism in Firefox that delays the loading of certain low-priority resources (typically third-party tracking resources) until higher-priority resources have finished loading. This helps improve page load performance by prioritizing resources that are critical for rendering and user interaction.

For information about how resource tailing integrates with Firefox’s overall network scheduling and prioritization system, see Firefox Network Scheduling and Prioritization.

How Resource Tailing Works

The Mechanism

  1. Request Context: Each page load has an associated nsIRequestContext that tracks the state of all network requests belonging to that context.

  2. Tailed vs Non-Tailed Requests:

    • Non-tailed requests are regular resources that load immediately

    • Tailed requests are delayed resources that are queued until certain conditions are met

    • The request context maintains a count of active non-tailed requests via AddNonTailRequest() and RemoveNonTailRequest()

  3. Tail Blocking Logic (see RequestContext::IsContextTailBlocked():

  4. Unblocking Conditions:

    • Time-based: A timer schedules when to unblock tailed requests. The delay is calculated as:

      • delay = quantum * mNonTailRequests (with maximum limits)

      • Default quantum decreases after DOMContentLoaded

      • The delay decreases progressively with time since page load began

    • Load completion: When non-tailed request count drops to zero after DOMContentLoaded

    • Forced unblocking: When the request context is canceled (e.g., navigation away)

  5. Implementation Flow

    AsyncOpen() or Connect()
      → WaitingForTailUnblock() checks if channel should be tailed
        → If yes: queued via IsContextTailBlocked()
        → mOnTailUnblock callback is set
      → Later: OnTailUnblock() is called
        → Executes the saved callback to continue operation
    

Eligibility for Tailing

A Resource is Eligible for Tailing When:

  1. Has the nsIClassOfService::Tail flag set

  2. Does NOT have any of these flags:

    • UrgentStart - User-initiated or high-priority requests

    • Leader - Blocking resources in document head

    • TailForbidden - Explicitly forbidden from tailing

  3. If marked Unblocked, must also have TailAllowed flag

  4. Is NOT a navigation request (IsNavigation() returns false)

Resources That Are Tailed

Primary Case: Third-Party Tracking Resources

Secondary Case: Async Scripts with TailAllowed

Resources That Are NEVER Tailed

2. Leader Resources (Critical Render-Blocking)

3. UrgentStart Resources (User-Initiated)

4. TailForbidden Resources

5. Other Unblocked Resources (without TailAllowed)

6. Resources with TailForbidden Override

Key Files and Interfaces

Core Interfaces

Implementation

Resource-Specific Code

Classification

HTTP/2 Priority Mapping

For HTTP/2 connections (see urgency calculation in nsHttpHandler::UrgencyFromCoSFlags():

  • Tailed resources get a special urgency level: network.http.tailing.urgency pref

  • See comments in nsIClassOfService.idl for full HTTP/2 priority tree documentation

Configuration Preferences

  • network.http.tailing.enabled: Master switch for tailing feature

  • network.http.tailing.urgency: HTTP/2 urgency level for tailed resources

  • Delay calculation parameters in nsHttpHandler

Child Process Handling

Summary

Resource tailing intelligently delays low-priority resources (primarily third-party trackers) to improve page load performance. The system uses:

  1. Class of Service flags to mark resource priority and tailing eligibility

  2. Request Contexts to manage tail queues per page load

  3. Time-based and load-based heuristics to determine when to unblock

  4. Strict rules to ensure critical resources (navigations, Leaders, UrgentStart) are never delayed

This creates a more responsive browsing experience by prioritizing resources that matter most to the user while still allowing tracking and analytics resources to eventually load.

Note that on some pages tailing can actually make the pageload slower. See bug 1962817 where the page hides the content until the tracking content loads.