Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Ajax

Ajax: Fix a Fetch Request Caching a Response Despite No-Store

- 21.11.26 - ErcanOPAK

🔄 Ajax: Fix a Fetch Request Caching a Response Despite No-Store

Setting cache: 'no-store' on a fetch() call controls how that request interacts with the browser’s HTTP cache, but it has no effect on a registered Service Worker’s own fetch event handler. If the Service Worker intercepts the request and serves a cached response from its own Cache Storage before the request would even reach the network layer where no-store takes effect, the page keeps seeing stale data regardless of the fetch option.

🔎 The Problem

// page code
const res = await fetch('/api/prices', { cache: 'no-store' });
// still returns a stale cached response

// service-worker.js
self.addEventListener('fetch', (event) => {
  event.respondWith(
    caches.match(event.request).then((cached) => cached || fetch(event.request))
    // caches.match() runs BEFORE the network layer ever sees
    // the request's cache: 'no-store' option
  );
});

✅ Fix: Check the Service Worker Before Blaming the HTTP Cache

  • Check whether a Service Worker is registered and intercepting requests to that endpoint (Application tab > Service Workers in DevTools) before assuming a stale response is an HTTP-cache problem that no-store should have fixed.
  • If the Service Worker’s strategy should bypass cache for a specific request, add a distinguishing marker (a query param, a custom header, or a URL pattern check) in its fetch handler so it explicitly skips caches.match() for that case.
  • For genuinely cache-busting calls from the page, append a cache-busting query parameter in addition to no-store, since that changes the request URL the Service Worker sees and can avoid matching an existing cache entry.

🚨 Why This Is Dangerous

  • Debugging a “stale data” issue by only inspecting network headers and fetch options can burn significant time when the actual culprit is a layer that runs before the network request is ever made, and the fix that seems obvious does nothing at all.

no-store tells the browser’s HTTP cache to stay out of the way — it says nothing to a Service Worker that already decided to answer the request itself.

— Frontend Engineer

Related posts:

Ajax: Fix Concurrent fetch() Calls to the Same Endpoint Triggering the Server's Rate Limiter Because...

Ajax: Fix Concurrent fetch() Calls to the Same Endpoint Triggering the Server's Rate Limiter Because...

Ajax: Fix a Chunked fetch() Response That Silently Truncates Because a Reverse Proxy Buffers and Cap...

Ajax: Fix a Chunked fetch() Response That Silently Truncates Because a Reverse Proxy Buffers and Cap...

Ajax: Understand CORS for Cross-Origin Requests

Ajax: Understand CORS for Cross-Origin Requests

Views: 8

Post navigation

WordPress: Fix a Navigation Block Losing Submenu Items After Sync
The AI Prompt That Audits a Function for Thread-Safety Gaps

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,068)
  • Get the User Name and Domain Name from an Email Address in SQL (990)
  • How to add default value for Entity Framework migrations for DateTime and Bool (986)
  • Get the First and Last Word from a String or Sentence in SQL (865)
  • How to select distinct rows in a datatable in C# (859)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (661)
  • Add Constraint to SQL Table to ensure email contains @ (619)
  • Average of all values in a column that are not zero in SQL (576)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (553)
  • Find numbers with more than two decimal places in SQL (481)

Recent Posts

  • Network Speed Monitor Windows Application v2.5.1
  • AÄŸ Hızı İzleyici Windows Uygulaması v2.5.1
  • How to make theater mode the default for Youtube
  • The AI Prompt That Audits a Function for Thread-Safety Gaps
  • Ajax: Fix a Fetch Request Caching a Response Despite No-Store
  • WordPress: Fix a Navigation Block Losing Submenu Items After Sync
  • Visual Studio: Fix CodeLens Reference Counts Stuck at Stale Numbers
  • C#: Fix a UTF-8 String Literal Behaving Differently in a Switch
  • Photoshop: Fix a Liquify Mesh Snapping Back on a Smart Object
  • The AI Prompt That Turns a Crash Dump Into a Short Repro Script

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,068)
  • Get the User Name and Domain Name from an Email Address in SQL (990)
  • How to add default value for Entity Framework migrations for DateTime and Bool (986)
  • Get the First and Last Word from a String or Sentence in SQL (865)
  • How to select distinct rows in a datatable in C# (859)

Recent Posts

  • Network Speed Monitor Windows Application v2.5.1
  • AÄŸ Hızı İzleyici Windows Uygulaması v2.5.1
  • How to make theater mode the default for Youtube
  • The AI Prompt That Audits a Function for Thread-Safety Gaps
  • Ajax: Fix a Fetch Request Caching a Response Despite No-Store

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com