Share via

Website styling broken after enabling Azure Front Door caching

Abdelrhman Goma 135 Reputation points
2026-03-19T14:59:27.45+00:00

Problem Description

We implemented Azure Front Door caching for our Next.js website hosted on Azure Container Apps to reduce costs, but the site styling is broken. Pages load without CSS initially, then flash to correct styling after a delay.

Current Setup

Front Door Profile: Standard tier

Origin: Azure Container Apps (Next.js application)

Route: /* with caching ENABLED

  • Rule Sets: 3 rules in this order:
  • User's image

What We've Verified

✅ HTML is NOT being cached (x-cache: CONFIG_NOCACHE)

✅ JS files ARE being cached (TCP_MISS → TCP_HIT)

✅ CSS files show proper cache headers from origin (max-age=31536000)

✅ Static assets are being cached after first request

The Issue

Despite correct caching behavior, the website:

Takes longer to load than before

Shows unstyled content initially

Then "pops" into correct styling after a delay

Sometimes styles are completely missing on first visit

Questions

Is there a specific order required for rules with Next.js applications?

Do we need to handle /_next/static/* paths differently?

Could there be a conflict between Front Door caching and Next.js automatic static optimization?

Is there a recommended caching strategy for Next.js apps on Container Apps?

How can we debug what's causing the delay between HTML load and CSS application?User's image

Azure Front Door
Azure Front Door

An Azure service that provides a cloud content delivery network with threat protection.

{count} votes

Answer accepted by question author
  1. Praveen Bandaru 10,900 Reputation points Microsoft External Staff Moderator
    2026-03-25T14:08:51.52+00:00

    Hello **Abdelrhman Goma
    **When accessing the front door domain, you are receiving partial content with 206 status code. Please check how the backend is responding. If you receive a 206 status code, it may indicate that the backend is compressing data, especially if compression is enabled at the backend level.

    Also, verify whether compression is enabled on both your backend and at the front door level. If compression is enabled on both sides, this behavior is expected.

    You should disable compression on either the backend or the front door. Additionally, cache also disabled on this scenarios.

    If you continue to experience issues after disabling compression, it could be due to a large backend file size and enabled compression on the backend.

    In such cases, implement a rule set to disable compression and accept encoding headers as shown in the screenshot.
    User's image

    If this rule doesn't work, you'll need to address the issue from your backend to reduce the size of the custom ranger headers.


    I hope the above answer helps you! Please let us know if you have any further questions.

    Please don't forget to "accept the answer" and "upvote" where the information provided will help you, this can be beneficial to other members of the community.

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Q&A Assist
    2026-03-19T14:59:57.41+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    Azure Front Door caching and rules do not have any Next.js‑specific ordering requirements in the documentation. The key guidance is to:

    • Cache only static assets (CSS, JS, images, fonts, etc.).
    • Avoid caching dynamic or user‑specific content (HTML pages, authenticated APIs).
    • Validate behavior with browser dev tools and the x-cache header.

    From the context:

    • Only GET requests are cacheable; other methods are always forwarded to origin.
    • Static assets such as images, CSS, and JavaScript files are ideal for caching.
    • Dynamic assets such as authenticated API endpoints should not be cached.
    • It is recommended to have separate routes for static and dynamic assets, with caching disabled for the latter.
    • For Power Pages, a working pattern is:
      • One route with caching enabled.
      • A rule set that:
        • Caches only specific static extensions (.css, .png, .jpg, .js, .svg, .woff, .ico) with an overridden cache duration (for example, 7 days).
        • Leaves page HTML uncached (x-cache: CONFIG_NOCACHE).
      • Validation via browser dev tools to ensure:
        • Static files show x-cache without NOCACHE.
        • Page requests show x-cache: CONFIG_NOCACHE.

    Applied to the described setup:

    1. Route configuration
      • Keep a single route like /* with Caching enabled.
      • Use Use Query String or Ignore Query String depending on whether query parameters affect static asset content.
      • Ensure HTTPS only and compression enabled as desired.
    2. Rule set strategy
      • Rule 1 (dynamic paths like /api, /auth, /login, etc.):
        • Condition: request path contains those segments.
        • Action: caching enabled at route level is fine, but rule should effectively result in no caching for these paths (for example, by honoring origin headers that set no-store/no-cache).
      • Rule 2: cache Next.js static assets
        • Condition: request path begins with /_next/static/.
        • Action: caching enabled, compression enabled, cache behavior override with a suitable TTL (for example, 7 days or longer if assets are content‑hashed).
      • Rule 3: cache other static assets
        • Condition: request path ends with static extensions such as .js, .css, .jpg, .png, .svg, .webp, .ico, .woff.
        • Action: caching enabled, compression enabled, cache behavior override with desired TTL.
      This mirrors the documented pattern where static files are cached and page content is not.
    3. Handling /_next/static/*

    The context explicitly recommends using routing rules to separate static and dynamic content and cache static content at the edge. Using a rule that matches /_next/static/ and caches those assets is aligned with this guidance.

    1. Debugging the delay between HTML and CSS

    The documentation recommends validating caching behavior with browser developer tools:

    • Open dev tools before loading the page.
    • On the Network tab:
      • Confirm that CSS and JS requests show x-cache without NOCACHE (indicating they are cacheable and can be served from edge).
      • Confirm that page HTML requests show x-cache: CONFIG_NOCACHE.
    • If x-cache for CSS or JS shows CONFIG_NOCACHE, the rule set is not matching as intended and those assets are not being cached at the edge, which can cause slower styling application.
    1. Recommended caching strategy for this scenario

    Based on the documented best practices:

    • Keep HTML and authenticated API responses uncached.
    • Cache all static assets (including /_next/static/* and other static file extensions) with a reasonable TTL.
    • Use rule sets to:
      • Match static assets by path or extension and enable caching with overridden TTL.
      • Ensure dynamic routes are not cached.
    • Validate with dev tools and x-cache headers after each rule change, noting that rule changes can take up to 10 minutes to propagate.

    This approach aligns with the documented pattern for Power Pages and the general Azure Front Door caching guidance and should avoid styling flashes caused by uncached or inconsistently cached CSS/JS.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.