Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CacheableResponsePlugin does ignore a specified header while routing a request #3290

Open
designdisorder opened this issue Jan 19, 2024 · 0 comments

Comments

@designdisorder
Copy link

designdisorder commented Jan 19, 2024

Library Affected:
workbox-sw

Browser & Platform:
Could only check Google Chrome

Issue Description:
I am using the CacheableResponsePlugin in a service worker definition to route cacheable and non-cacheable documents with two different caching strategies. If the header "pwa-cache-control: no-cache" is set in the response I'd like to apply the NetworkOnly strategy and in case the header is missing CacheFirst.

What actually happens though, all documents are handled by the NetworkOnly route, no matter if the pwa-cache-control header is present or missing. I could verify that in the debug view. Do I miss something here or is the header feature of the plugin broken?

If I remove the first route, the CacheFirst strategy is used as expected for all documents.

Btw, with this approach I am assuming that routes are considered in the order of being registered, correct?

Here is the respective section within my sw.js

// don't cache pages with no-cache header
registerRoute(
	({request}) => request.destination === 'document',
	new NetworkOnly({
		plugins: [
			new CacheableResponsePlugin({
				headers: {
					'pwa-cache-control': 'no-cache',
				},
			}),
		],
	})
);

// but cache other pages
registerRoute(
	({request}) => request.destination === 'document',
	new CacheFirst({
		cacheName: 'html-cache',
		plugins: [
			new ExpirationPlugin({
				maxAgeSeconds: 7 * 24 * 60 * 60,
			}),
		],
	})
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant