Skip to content

Instantly share code, notes, and snippets.

View MrPeker's full-sized avatar
🎯
Focusing

Mehmet Ali Peker MrPeker

🎯
Focusing
View GitHub Profile
@MrPeker
MrPeker / consoleLog.js
Last active November 9, 2019 22:09
Customize your console log output for don't ask "this output from which line?"
let log = console.log;
console.log = function() {
log("");
log.apply(console, arguments);
let info = new Error().stack.split(' at ')[2].trim().split(__dirname);
log('-- from', '\x1b[33m', info[0].split(' (')[0], '\x1b[0m', 'at', '\x1b[33m', info[1], '\x1b[0m');
};
workbox.routing.registerRoute(
match,
workbox.strategies.staleWhileRevalidate()
);
workbox.routing.registerRoute(
match,
workbox.strategies.networkFirst()
);
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',
})
);
workbox.routing.registerRoute(
new RegExp('.*\.js'),
workbox.strategies.networkFirst()
);
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(
const handler = ({url, event}) => {
return new Response(`Custom handler response.`);
};
workbox.routing.registerRoute(match, handler);
workbox.strategies.staleWhileRevalidate({
// Bu rota için özel isim kullan
cacheName: 'my-cache-name',
// Özel eklentiler dizisi ekle (örneğin workbox.expiration.Plugin)
plugins: [
...
]
});
@MrPeker
MrPeker / offline-google-analytics.js
Created January 27, 2019 18:12
Offline Google Analytics Workbox
workbox.googleAnalytics.initialize();
@MrPeker
MrPeker / cache-images.js
Last active January 27, 2019 18:08
Cache Images Workbox
// 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
// Stale While Revalidate stratejisiyle CSS ve JS varlıklarınızı önbellekleyin
workbox.routing.registerRoute(
/\.(?:js|css)$/,
workbox.strategies.staleWhileRevalidate(),
);