惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
Google DeepMind News
Google DeepMind News
博客园 - 【当耐特】
量子位
博客园 - 司徒正美
爱范儿
爱范儿
Hugging Face - Blog
Hugging Face - Blog
博客园 - 聂微东
Jina AI
Jina AI
J
Java Code Geeks
腾讯CDC
大猫的无限游戏
大猫的无限游戏
V
Visual Studio Blog
I
InfoQ
D
Docker
Recent Announcements
Recent Announcements
MongoDB | Blog
MongoDB | Blog
博客园 - Franky
宝玉的分享
宝玉的分享
G
Google Developers Blog
GbyAI
GbyAI
Y
Y Combinator Blog
有赞技术团队
有赞技术团队
H
Help Net Security

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
🔀Advanced provideHttpClient Interceptors
abdelaaziz o · 2026-05-12 · via DEV Community

Most Angular apps are still stuck in 2019’s interceptor model. Angular 20 quietly killed it — here’s why your pipeline needs a rewrite

Most Angular applications still use interceptor architecture designed for Angular 8.

The old pattern:

@NgModule({
  providers: [
    { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true }
  ]
})

Enter fullscreen mode Exit fullscreen mode

Three problems with this:

  1. Order is implicit — You can't visually trace the pipeline
  2. Tree shaking is impossible — All interceptors bundle regardless of usage
  3. Testing requires TestBed — No pure function testing

Angular 20+ changed everything with provideHttpClient().

The modern approach:

// main.ts
export const appConfig: ApplicationConfig = {
  providers: [
    provideHttpClient(
      withInterceptors([
        authInterceptor,
        retryInterceptor,
        loggingInterceptor,
        errorInterceptor,
        cacheInterceptor
      ])
    )
  ]
};

// functional interceptor
export const authInterceptor: HttpInterceptorFn = (req, next) => {
  const auth = inject(AuthService);
  const token = auth.getToken();

  const reqWithAuth = req.clone({
    headers: req.headers.set('Authorization', `Bearer ${token}`)
  });

  return next(reqWithAuth);
};

Enter fullscreen mode Exit fullscreen mode

Why this wins:

✅ Composition is explicit — Order matches array sequence.
✅ Tree shakeable — Unused interceptors never hit the bundle.
✅ Pure testable — No TestBed required for unit tests.
✅ Standalone-first — No NgModule wrapper needed.
✅ inject() works — DI inside functional interceptors.

Here’s how the new explicit pipeline visually compares to the old implicit stack

Interceptor pipeline diagram
Visual comparison: implicit NgModule stack vs explicit provideHttpClient array order.

The Senior Architect Golden Rule:

Networking architecture should scale as cleanly as UI architecture.

Your interceptor chain is middleware. Treat it like one.


🧱 From syntax to system design

Enterprise reality check:

Large Angular apps fail when networking concerns:

  • Centralize into one monolithic interceptor.
  • Mix authentication, logging, retry, and caching.
  • Create circular DI dependencies.
  • Block SSR with browser-only APIs.

Modern solution: Composable pipelines with isolated concerns.

// Each interceptor does ONE thing
export const retryInterceptor: HttpInterceptorFn = (req, next) => {
  return next(req).pipe(
    retry({
      count: 3,
      delay: exponentialBackoff(1000, 5000)
    })
  );
};

Enter fullscreen mode Exit fullscreen mode

Performance impact:

Old NgModule pattern: All interceptors bundle → ~8-12KB dead code
Functional pattern: Only used interceptors → 0KB dead code

Angular bundle size comparison
Bundle size diff: Old NgModule pattern vs Functional Interceptors — 8.2 kB saved 🚀

SSR consideration:

Your interceptors need to check the execution environment:

export const browserOnlyInterceptor: HttpInterceptorFn = (req, next) => {
  if (isPlatformServer(inject(PLATFORM_ID))) {
    return next(req);
  }
  // Browser-specific logic
  return next(req).pipe(tap(/* analytics */));
};

Enter fullscreen mode Exit fullscreen mode

What's the most complex interceptor chain you've built in production? And is it still using HTTP_INTERCEPTORS?

If you’ve migrated to functional interceptors, share your bundle diff or lessons below — I’d love to see how your pipeline evolved.

🌐 Connect With Me
If you enjoyed this deep dive into Angular architecture and want more insights on scalable frontend systems, follow my work across platforms:

🔗 LinkedIn — Professional discussions, architecture breakdowns, and engineering insights.
📸 Instagram — Visuals, carousels, and design‑driven posts under the Terminal Elite aesthetic.
🧠 Website — Articles, tutorials, and project showcases.
🎥 YouTube — Deep‑dive videos and live coding sessions.