Commit ac290ea0 authored by Andres Käver's avatar Andres Käver
Browse files

pwa

parent 6ed38c8f
webpackHotUpdate("app",{
/***/ "./src/index.ts":
/*!**********************!*\
!*** ./src/index.ts ***!
\**********************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("\nconst neworkStatusChangeFn = (status, e) => {\n console.log('neworkStatusChangeFn', status, e);\n const elem = document.querySelector('#networkStatus');\n if (elem)\n elem.innerHTML = status;\n};\nwindow.addEventListener('offline', function (e) { neworkStatusChangeFn('offline', e); });\nwindow.addEventListener('online', function (e) { neworkStatusChangeFn('online', e); });\nneworkStatusChangeFn(navigator.onLine ? 'online' : 'offline');\n\n\n//# sourceURL=webpack:///./src/index.ts?");
/***/ })
})
\ No newline at end of file
{"h":"dac33eab4e76c8acd77a","c":{"app":true}}
\ No newline at end of file
......@@ -13,7 +13,7 @@
/******/ function hotDownloadUpdateChunk(chunkId) {
/******/ var script = document.createElement("script");
/******/ script.charset = "utf-8";
/******/ script.src = __webpack_require__.p + "4ea57b6-" + chunkId + "-wps-hmr.js";
/******/ script.src = __webpack_require__.p + "05973a8-" + chunkId + "-wps-hmr.js";
/******/ if (null) script.crossOrigin = null;
/******/ document.head.appendChild(script);
/******/ }
......@@ -27,7 +27,7 @@
/******/ }
/******/ try {
/******/ var request = new XMLHttpRequest();
/******/ var requestPath = __webpack_require__.p + "4ea57b6-wps-hmr.json";
/******/ var requestPath = __webpack_require__.p + "05973a8-wps-hmr.json";
/******/ request.open("GET", requestPath, true);
/******/ request.timeout = requestTimeout;
/******/ request.send(null);
......@@ -63,7 +63,7 @@
/******/
/******/ var hotApplyOnUpdate = true;
/******/ // eslint-disable-next-line no-unused-vars
/******/ var hotCurrentHash = "2f0ce09be9f32ff60985";
/******/ var hotCurrentHash = "dac33eab4e76c8acd77a";
/******/ var hotRequestTimeout = 10000;
/******/ var hotCurrentModuleData = {};
/******/ var hotCurrentChildModule;
......@@ -282,7 +282,7 @@
/******/ };
/******/ });
/******/ hotUpdate = {};
/******/ var chunkId = "main";
/******/ var chunkId = "app";
/******/ // eslint-disable-next-line no-lone-blocks
/******/ {
/******/ hotEnsureUpdateChunk(chunkId);
......@@ -866,7 +866,7 @@
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
eval("/*\n Copyright © 2018 Andrew Powell\n\n This Source Code Form is subject to the terms of the Mozilla Public\n License, v. 2.0. If a copy of the MPL was not distributed with this\n file, You can obtain one at http://mozilla.org/MPL/2.0/.\n\n The above copyright notice and this permission notice shall be\n included in all copies or substantial portions of this Source Code Form.\n*/\n\n/**\n * @note This file exists merely as an easy reference for folks adding it to their configuration entries\n */\n\n(() => {\n /* eslint-disable global-require */\n const { run } = __webpack_require__(/*! ./lib/client/client */ \"./node_modules/webpack-plugin-serve/lib/client/client.js\");\n let hash = '<unknown>';\n let options;\n try {\n options = {\"compress\":{},\"headers\":null,\"historyFallback\":false,\"hmr\":true,\"host\":null,\"liveReload\":false,\"log\":{\"level\":\"info\",\"prefix\":{\"template\":\"{{level}}\"},\"name\":\"webpack-plugin-serve\"},\"open\":false,\"port\":8089,\"progress\":true,\"ramdisk\":false,\"secure\":false,\"static\":[\"./dist\",\"./wwwroot\"],\"status\":true,\"client\":{\"silent\":false},\"address\":\"[::]:8089\",\"compilerName\":null,\"wpsId\":\"4ea57b6\"};\n } catch (e) {\n const { log } = __webpack_require__(/*! ./lib/client/log */ \"./node_modules/webpack-plugin-serve/lib/client/log.js\");\n log.error(\n 'The entry for webpack-plugin-serve was included in your build, but it does not appear that the plugin was. Please check your configuration.'\n );\n }\n\n try {\n // eslint-disable-next-line camelcase\n hash = __webpack_require__.h();\n } catch (e) {} // eslint-disable-line no-empty\n\n run(hash, options);\n})();\n\n\n//# sourceURL=webpack:///(webpack)-plugin-serve/client.js?");
eval("/*\n Copyright © 2018 Andrew Powell\n\n This Source Code Form is subject to the terms of the Mozilla Public\n License, v. 2.0. If a copy of the MPL was not distributed with this\n file, You can obtain one at http://mozilla.org/MPL/2.0/.\n\n The above copyright notice and this permission notice shall be\n included in all copies or substantial portions of this Source Code Form.\n*/\n\n/**\n * @note This file exists merely as an easy reference for folks adding it to their configuration entries\n */\n\n(() => {\n /* eslint-disable global-require */\n const { run } = __webpack_require__(/*! ./lib/client/client */ \"./node_modules/webpack-plugin-serve/lib/client/client.js\");\n let hash = '<unknown>';\n let options;\n try {\n options = {\"compress\":{},\"headers\":null,\"historyFallback\":false,\"hmr\":true,\"host\":null,\"liveReload\":false,\"log\":{\"level\":\"info\",\"prefix\":{\"template\":\"{{level}}\"},\"name\":\"webpack-plugin-serve\"},\"open\":false,\"port\":8089,\"progress\":true,\"ramdisk\":false,\"secure\":false,\"static\":[\"./dist\",\"./wwwroot\"],\"status\":true,\"client\":{\"silent\":false},\"address\":\"[::]:8089\",\"compilerName\":null,\"wpsId\":\"05973a8\"};\n } catch (e) {\n const { log } = __webpack_require__(/*! ./lib/client/log */ \"./node_modules/webpack-plugin-serve/lib/client/log.js\");\n log.error(\n 'The entry for webpack-plugin-serve was included in your build, but it does not appear that the plugin was. Please check your configuration.'\n );\n }\n\n try {\n // eslint-disable-next-line camelcase\n hash = __webpack_require__.h();\n } catch (e) {} // eslint-disable-line no-empty\n\n run(hash, options);\n})();\n\n\n//# sourceURL=webpack:///(webpack)-plugin-serve/client.js?");
/***/ }),
......@@ -966,7 +966,7 @@ eval("/*\n Copyright © 2018 Andrew Powell\n\n This Source Code Form is subjec
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("\n\n\n//# sourceURL=webpack:///./src/index.ts?");
eval("\nconst neworkStatusChangeFn = (status, e) => {\n console.log('neworkStatusChangeFn', status, e);\n const elem = document.querySelector('#networkStatus');\n if (elem)\n elem.innerHTML = status;\n};\nwindow.addEventListener('offline', function (e) { neworkStatusChangeFn('offline', e); });\nwindow.addEventListener('online', function (e) { neworkStatusChangeFn('online', e); });\nneworkStatusChangeFn(navigator.onLine ? 'online' : 'offline');\n\n\n//# sourceURL=webpack:///./src/index.ts?");
/***/ }),
......
"use strict";
// for testing on mobile device - host it over https
const CACHE = 'cache-0.0.2';
const urlsToPrefetch = [
'/css/style.css'
];
self.addEventListener('install', ((event) => {
console.log('before waituntil');
const installFn = async () => {
try {
const cache = await caches.open(CACHE);
return await cache.addAll(urlsToPrefetch);
}
catch (err) {
console.error(err, typeof (err));
return Promise.reject(err);
}
};
// waitUntil parameter is a Promise (not an function that returns promise)
event.waitUntil(installFn());
}));
self.addEventListener('activate', ((event) => {
const activateFn = async () => {
const cacheKeyList = await caches.keys();
cacheKeyList.map(async (cacheKey) => {
if (cacheKey != CACHE) {
console.log('Deleting from cache: ' + cacheKey);
await caches.delete(cacheKey);
}
});
};
event.waitUntil(activateFn());
}));
self.addEventListener('fetch', ((event) => {
console.log('SW fetch', event);
const fetchFn = async (event) => {
const cache = await caches.open(CACHE);
const getCachedResponse = async (request) => {
const cacheResponse = await cache.match(event.request);
console.log('Cache response', cacheResponse);
if (cacheResponse != undefined)
return cacheResponse;
return new Response(undefined, { status: 500, statusText: 'Nothing in cache!' });
};
if (navigator.onLine) {
try {
const response = await fetch(event.request);
cache.put(event.request, response.clone());
return response;
}
catch (err) {
console.log('Fetch failed, trying cache', err);
const cacheResponse = await getCachedResponse(event.request);
return cacheResponse;
}
}
else {
console.log('navigator.onLine', navigator.onLine);
const cacheResponse = await getCachedResponse(event.request);
return cacheResponse;
}
};
event.respondWith(fetchFn(event));
/*
event.respondWith(
fetch(event.request).then(response => {
console.log('fetch response', response);
return response;
})
);
*/
}));
//# sourceMappingURL=sw.js.map
\ No newline at end of file
{"version":3,"file":"sw.js","sourceRoot":"","sources":["../src/sw/sw.ts"],"names":[],"mappings":";AAAA,oDAAoD;AAEpD,MAAM,KAAK,GAAG,aAAa,CAAA;AAE3B,MAAM,cAAc,GAAG;IACnB,gBAAgB;CACnB,CAAC;AAEF,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC,CAAC,KAAsB,EAAQ,EAAE;IAC/D,OAAO,CAAC,GAAG,CA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\ No newline at end of file
This diff is collapsed.
......@@ -5,8 +5,8 @@
"main": "index.js",
"scripts": {
"test": "echo \"My code is perfect anyway! No tests!\" && exit 0",
"build": "webpack --mode production",
"start": "webpack"
"build": "tsc --project ./src/sw/tsconfig.json --outDir ./dist && webpack --mode production",
"start": "tsc --project ./src/sw/tsconfig.json --outDir ./dist && webpack"
},
"author": "",
"license": "ISC",
......@@ -14,6 +14,7 @@
"ts-loader": "^8.0.11",
"typescript": "^4.0.5",
"webpack": "^4.44.2",
"webpack-cli": "^4.2.0",
"webpack-nano": "^1.1.0",
"webpack-plugin-serve": "^1.2.0"
}
......
const neworkStatusChangeFn = (status: string, e?: Event): void => {
console.log('neworkStatusChangeFn', status, e);
const elem = document.querySelector('#networkStatus');
if (elem) elem.innerHTML = status;
}
window.addEventListener('offline', function (e) { neworkStatusChangeFn('offline', e); });
window.addEventListener('online', function (e) { neworkStatusChangeFn('online',e ); });
neworkStatusChangeFn(navigator.onLine ? 'online' : 'offline');
// for testing on mobile device - host it over https
const CACHE = 'cache-0.0.2'
const urlsToPrefetch = [
'/css/style.css'
];
self.addEventListener('install', ((event: ExtendableEvent): void => {
console.log('before waituntil');
const installFn = async (): Promise<void> => {
try {
const cache = await caches.open(CACHE);
return await cache.addAll(urlsToPrefetch);
} catch (err) {
console.error(err, typeof (err));
return Promise.reject(err);
}
};
// waitUntil parameter is a Promise (not an function that returns promise)
event.waitUntil(installFn());
}) as EventListener);
self.addEventListener('activate', ((event: ExtendableEvent): void => {
const activateFn = async (): Promise<void> => {
const cacheKeyList = await caches.keys();
cacheKeyList.map(async (cacheKey) => {
if (cacheKey != CACHE) {
console.log('Deleting from cache: ' + cacheKey);
await caches.delete(cacheKey);
}
});
};
event.waitUntil(activateFn());
}) as EventListener);
self.addEventListener('fetch', ((event: FetchEvent): void => {
console.log('SW fetch', event);
const fetchFn = async (event: FetchEvent): Promise<Response> => {
const cache = await caches.open(CACHE);
const getCachedResponse = async (request: RequestInfo): Promise<Response> => {
const cacheResponse = await cache.match(event.request);
console.log('Cache response', cacheResponse);
if (cacheResponse != undefined) return cacheResponse;
return new Response(undefined, { status: 500, statusText: 'Nothing in cache!' });
}
if (navigator.onLine) {
try {
const response = await fetch(event.request);
cache.put(event.request, response.clone());
return response;
} catch (err) {
console.log('Fetch failed, trying cache', err);
const cacheResponse = await getCachedResponse(event.request);
return cacheResponse;
}
} else {
console.log('navigator.onLine', navigator.onLine);
const cacheResponse = await getCachedResponse(event.request);
return cacheResponse;
}
};
event.respondWith(fetchFn(event));
/*
event.respondWith(
fetch(event.request).then(response => {
console.log('fetch response', response);
return response;
})
);
*/
}) as EventListener);
{
"compilerOptions": {
"module": "esnext",
"target": "es2017",
"strict": true,
"alwaysStrict": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"esModuleInterop": true,
"sourceMap": true,
"lib": [
"ESNext",
"WebWorker"
]
},
"include": [
"global.d.ts", "./*"
],
"exclude": [
"node_modules"
]
}
\ No newline at end of file
......@@ -13,12 +13,14 @@ const options = {
module.exports = {
mode: 'development',
entry: [
'./src/index.ts',
'webpack-plugin-serve/client'
],
entry: {
'app': [
'./src/index.ts',
'webpack-plugin-serve/client'
]
},
output: {
filename: 'app.js',
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
},
resolve: {
......
......@@ -17,17 +17,21 @@
<link href="css/materialize.css" type="text/css" rel="stylesheet" media="screen,projection" />
<link href="css/style.css" type="text/css" rel="stylesheet" media="screen,projection" />
<script>
if ('serviceWorker' in navigator){
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js').then(
function () {console.log('ServiceWorker registered!')}
);
function () { console.log('ServiceWorker registered!') }
).catch(err => {
console.error('ServiceWorker error', err);
});
}
</script>
</head>
<body>
<nav class="light-blue lighten-1" role="navigation">
<div class="nav-wrapper container"><a id="logo-container" href="#" class="brand-logo">Logo</a>
<div class="nav-wrapper container">
<a id="logo-container" href="#" class="brand-logo">Logo <span id="networkStatus">---</span></a>
<ul class="right hide-on-med-and-down">
<li><a href="#">Navbar Link</a></li>
</ul>
......@@ -68,6 +72,7 @@
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="js/materialize.js"></script>
<script src="js/init.js"></script>
<script src="/app.js"></script>
</body>
......
self.addEventListener('install', function (event) {
console.log('SW install', event);
});
self.addEventListener('activate', function (event) {
console.log('SW activate', event);
});
self.addEventListener('fetch', function (event) {
console.log('SW fetch', event);
event.respondWith(
fetch(event.request).then(response => {
console.log('fetch response', response);
return response;
})
);
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment