Skip to content

Instantly share code, notes, and snippets.

@divyasonaraa
Created November 27, 2023 08:17
Show Gist options
  • Save divyasonaraa/d990fab0cc8d9bd5383216849944d9f2 to your computer and use it in GitHub Desktop.
Save divyasonaraa/d990fab0cc8d9bd5383216849944d9f2 to your computer and use it in GitHub Desktop.
//Cache first, falling back to network
registerRoute(
({ url }) => url.host.startsWith("fonts.googleapi.com"),
new CacheFirst({
cacheName: "google-fonts",
plugins: [
new ExpirationPlugin({
maxEntries: 30,
}),
new CacheableResponsePlugin({
statuses: [0, 200],
}),
],
})
);
//Network first, falling back to cache
registerRoute(
({ url }) => url.pathname.startsWith("/blogs"),
new NetworkFirst()
);
//Stale-while-revalidate
registerRoute(
({ url }) => url.protocol === "http:" || url.protocol === "https:",
new StaleWhileRevalidate()
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment