Skip to content

Commit

Permalink
attempt to add service_workd and manifest, #55
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonLab committed Dec 13, 2019
1 parent 6066d71 commit 114f293
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 2 deletions.
Binary file added assets/static/images/favicon.ico
Binary file not shown.
25 changes: 25 additions & 0 deletions assets/static/js/service_worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
self.addEventListener('install', function(e) {
e.waitUntil(
caches.open('progessive-elm').then(function(cache) {
return cache.addAll([
'/elm/capture',
]);
})
);
});

self.addEventListener('fetch', function(event) {
console.log('Service Worker Intercept: ' + event.request.url);

event.respondWith(

caches.match(event.request).then(function(response) {

console.log('Service Worker Serve: ' + event.request.url);

return response || fetch(event.request);

})

);
});
15 changes: 15 additions & 0 deletions assets/static/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "DWYL App",
"name": "Spike using progressive web app",
"icons": [
{
"src": "/images/favicon.ico",
"sizes": "192x192",
"type": "image/png"
}
],
"start_url": "/",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
2 changes: 1 addition & 1 deletion lib/app_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule AppWeb.Endpoint do
at: "/",
from: :app,
gzip: false,
only: ~w(css fonts images js favicon.ico robots.txt)
only: ~w(css fonts images js favicon.ico robots.txt cache_manifest.json service_worker.js)

# Code reloading can be explicitly enabled under the
# :code_reloader configuration of your endpoint.
Expand Down
2 changes: 1 addition & 1 deletion lib/app_web/templates/capture/init_elm.html.eex
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<h1>Elm PWA</h1>

<div id="elm-app"></div>
<div id="elm-app"></div>
8 changes: 8 additions & 0 deletions lib/app_web/templates/layout/app.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<link rel="icon" type="image/png" sizes="32x32" href="https://dwyl.com/img/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="https://dwyl.com/img/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="https://dwyl.com/img/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
</head>
<body class="bg-near-white helvetica">
<header class="pa3">
Expand All @@ -35,5 +36,12 @@
<%= render @view_module, @view_template, assigns %>
</main>
<script type="text/javascript" src="<%= Routes.static_path(@conn, "/js/app.js") %>"></script>
<script>
if('serviceWorker' in navigator) {
navigator.serviceWorker
.register('/js/service_worker.js')
.then(function() { console.log("Service Worker Registered"); });
}
</script>
</body>
</html>

0 comments on commit 114f293

Please sign in to comment.