Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add service worker logic and site manifest #107

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added website/public/favicon.ico
Binary file not shown.
Binary file added website/public/img/icon-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added website/public/img/screenshot1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added website/public/img/screenshot2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions website/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
<meta charset="UTF-8">
<title>JoliTypo demo - Micro-typography fixer for HTML contents</title>
<link rel="stylesheet" href="./css/app.css">
<link rel="manifest" href="./site.webmanifest">
<link rel="icon" href="favicon.ico" />
<script type="module">
import {Workbox} from '/workbox/workbox-window.prod.mjs';
if ('serviceWorker' in navigator) {
const wb = new Workbox('/sw.js', {scope: '/', useCache: true});
wb.register();
window.workbox = wb;
}
</script>
</head>

<body class="u-bgc(whitegradient)">
Expand Down
45 changes: 45 additions & 0 deletions website/public/site.webmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"description": "This is a sample page to let you try out our microtypography fixer.",
"name": "JoliTypo",
"short_name": "JoliTypo",
"start_url": "/",
"background_color": "#2b2b2a",
"display": "standalone",
"display_override": [
"fullscreen",
"minimal-ui",
"window-controls-overlay"
],
"icons": [
{
"src": "/images/icon-192x192.png",
"sizes": "48x48 72x72 96x96 144x144 180x180 192x192",
"type": "image/png"
}
],
"screenshots": [
{
"src": "/images/screenshot1.png",
"sizes": "1718x1303",
"form_factor": "wide",
"label": "Main screen",
"type": "image/png"
},
{
"src": "/images/screenshot2.png",
"sizes": "678x1303",
"form_factor": "narrow",
"label": "Main screen",
"type": "image/png"
}
],
"id": "/",
"orientation": "any",
"scope": "/",
"theme_color": "#2b2b2a",
"serviceworker": {
"src": "/sw.js",
"scope": "/",
"use_cache": true
}
}
52 changes: 52 additions & 0 deletions website/public/sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**************************************************** WORKBOX IMPORT ****************************************************/
importScripts('/workbox/workbox-sw.js');
workbox.setConfig({modulePathPrefix: '/workbox'});
/**************************************************** END WORKBOX IMPORT ****************************************************/

/**************************************************** CACHE STRATEGY ****************************************************/
//Static assets
const cache_0_0 = new workbox.strategies.CacheFirst({
cacheName: 'assets',plugins: [new workbox.cacheableResponse.CacheableResponsePlugin({
"statuses": [
0,
200
]
}), new workbox.expiration.ExpirationPlugin({
"maxEntries": 61,
"maxAgeSeconds": 31536000
})]
});
workbox.routing.registerRoute(({url, request}) => url.pathname.startsWith('/build') || request.destination === 'font' || request.destination === 'image' || request.destination === 'style' || request.destination === 'script' || request.destination === 'manifest',cache_0_0);

/**************************************************** CACHE CLEAR ****************************************************/
// The configuration is set to clear all caches on each install event
self.addEventListener("install", function (event) {
event.waitUntil(caches.keys().then(function (cacheNames) {
return Promise.all(
cacheNames.map(function (cacheName) {
return caches.delete(cacheName);
})
);
})
);
});
/**************************************************** END CACHE CLEAR ****************************************************/

/**************************************************** OFFLINE FALLBACK ****************************************************/
// The configuration is set to use the network only strategy by default
workbox.routing.setDefaultHandler(new workbox.strategies.NetworkOnly());
workbox.recipes.offlineFallback({
"pageFallback": "/"
});
/**************************************************** END OFFLINE FALLBACK ****************************************************/


/**************************************************** SKIP WAITING ****************************************************/
// The configuration is set to skip waiting on each install event
self.addEventListener("install", function (event) {
event.waitUntil(self.skipWaiting());
});
self.addEventListener("activate", function (event) {
event.waitUntil(self.clients.claim());
});
/**************************************************** END SKIP WAITING ****************************************************/
2 changes: 2 additions & 0 deletions website/public/workbox/workbox-background-sync.prod.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions website/public/workbox/workbox-background-sync.prod.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions website/public/workbox/workbox-broadcast-update.prod.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading