Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Mehmet Ali Peker MrPeker

🎯
Focusing
View GitHub Profile
View workbox-routing-example.js
workbox.routing.registerRoute(
// CSS dosyalarını önbellekle
/.*\.css/,
// Önbelleği kullan ama mümkün olduğunda arkaplanda güncelle
workbox.strategies.staleWhileRevalidate({
// Özel önbellek ismi kullan
cacheName: 'css-cache',
})
);
View workbox-js-file-network-first-strategy.js
workbox.routing.registerRoute(
new RegExp('.*\.js'),
workbox.strategies.networkFirst()
);
View handling-route-custom-callback-params.js
const match = ({url, event}) => {
return {
name: 'Workbox',
type: 'guide',
};
};
const handler = ({url, event, params}) => {
// Yanıt “A guide on Workbox” olacaktır
return new Response(
View handling-route-custom-callback.js
const handler = ({url, event}) => {
return new Response(`Custom handler response.`);
};
workbox.routing.registerRoute(match, handler);
View workbox-strategy-options.js
workbox.strategies.staleWhileRevalidate({
// Bu rota için özel isim kullan
cacheName: 'my-cache-name',
// Özel eklentiler dizisi ekle (örneğin workbox.expiration.Plugin)
plugins: [
...
]
});
View cache-strategy-handler.js
workbox.routing.registerRoute(
match,
workbox.strategies.staleWhileRevalidate()
);
workbox.routing.registerRoute(
match,
workbox.strategies.networkFirst()
);
@MrPeker
MrPeker / offline-google-analytics.js
Created January 27, 2019 18:12
Offline Google Analytics Workbox
View offline-google-analytics.js
workbox.googleAnalytics.initialize();
@MrPeker
MrPeker / cache-images.js
Last active January 27, 2019 18:08
Cache Images Workbox
View cache-images.js
// Cache First stratejisiyle resimlerinizi önbellekleyin
workbox.routing.registerRoute(
/\.(?:png|gif|jpg|jpeg|svg)$/,
workbox.strategies.cacheFirst({
cacheName: 'images',
plugins: [
new workbox.expiration.Plugin({
maxEntries: 60,
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Gün
}),
@MrPeker
MrPeker / cache-js-css.js
Created January 27, 2019 18:03
Cache Javascript and CSS Workbox
View cache-js-css.js
// Stale While Revalidate stratejisiyle CSS ve JS varlıklarınızı önbellekleyin
workbox.routing.registerRoute(
/\.(?:js|css)$/,
workbox.strategies.staleWhileRevalidate(),
);
@MrPeker
MrPeker / cache-google-fonts.js
Created January 27, 2019 17:57
Cache Google Fonts - Webpack
View cache-google-fonts.js
// Google Fonts stil dosyalarını Stale While Revalidate stratejisi ile önbellekleyin
workbox.routing.registerRoute(
/^https:\/\/fonts\.googleapis\.com/,
workbox.strategies.staleWhileRevalidate({
cacheName: 'google-fonts-stylesheets',
}),
);
// Google Fonts webfont dosyalarını Cache First stratejisiyle bir yıllığına önbellekleyin
workbox.routing.registerRoute(