Skip to content

Instantly share code, notes, and snippets.

View jadjoubran's full-sized avatar
Building learnjavascript.online & react-tutorial.app

Jad Joubran jadjoubran

Building learnjavascript.online & react-tutorial.app
View GitHub Profile
importScripts('https://cdn.jsdelivr.net/npm/[email protected]/comlink.global.min.js');
class Fetch {
constructor()
getBaseUrl()
getDefaultHeaders()
getDefaultBody()
setBaseUrl(baseUrl)
import { Comlink } from './node_modules/comlinkjs/comlink.es6.js';
const worker = new Worker('./node_modules/comlink-fetch/src/fetch.worker.js');
const proxy = Comlink.proxy(worker);
async function getSecondaryInfo() {
const API = await new proxy.Fetch;
API.setBaseUrl("https://jsonplaceholder.typicode.com/");
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Comlink Fetch</title>
</head>
<body>
<script type="module" src="index.js"></script>
workbox.routing.registerRoute(
new RegExp('https://jsonplaceholder.typicode.com/users'),
workbox.strategies.cacheFirst()
);
workbox.strategies.cacheFirst()
workbox.strategies.networkFirst()
workbox.strategies.staleWhileRevalidate()
importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.0.0/workbox-sw.js');
console.log('this is my custom service worker');
workbox.precaching.precacheAndRoute([
{
"url": "css/app.css",
"revision": "fd2e1d3c4c8d43da10afe67a7d69fbd1"
},
{
"url": "index.html",
"revision": "39b8fb34f8be7ecf969530f1b9e69ba1"
module.exports = {
"globDirectory": "build/",
"globPatterns": [
"**/*.{css,html,js}"
],
"swDest": "build/sw.js",
"swSrc": "src-sw.js"
};
importScripts('https://storage.googleapis.com/workbox-cdn/releases/3.0.0/workbox-sw.js');
console.log('this is my custom service worker');
workbox.precaching.precacheAndRoute([]);
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js');
});
}
</script>
module.exports = {
"globDirectory": "build/",
"globPatterns": [
"**/*.{css,html,js}"
],
"swDest": "build/sw.js"
};