#view
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Hello World</title>
<link rel="manifest" href="/pwa/manifest.json">
<link rel="stylesheet" href="/pwa/static/css/style.css">
<link rel="icon" href="/pwa/static/favicon.ico" type="image/x-icon" />
<link rel="apple-touch-icon" href="/pwa/static/images/hello-icon-152.png">
<meta name="theme-color" content="#DE3C4B" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="white"/>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="Hello World">
<meta name="msapplication-TileImage" content="/pwa/static/images/hello-icon-144.png">
<meta name="msapplication-TileColor" content="#FFFFFF">
</head>
<body class="fullscreen">
<div class="container">
<h1 class="title">Hello World!</h1>
</div>
<script src="/pwa/main.js"></script>
</body>
</html>
Write functions to return the three files instead. Dont put actual files in static folder
#controller
def manifest():
response.headers['Content-Type'] = 'text/json'
return '''
{
"name": "Hello World",
"short_name": "Hello",
"icons": [{
"src": "/pwa/static/images/hello-icon-128.png",
"sizes": "128x128",
"type": "image/png"
}, {
"src": "/pwa/static/images/hello-icon-144.png",
"sizes": "144x144",
"type": "image/png"
}, {
"src": "/pwa/static/images/hello-icon-152.png",
"sizes": "152x152",
"type": "image/png"
}, {
"src": "/pwa/static/images/hello-icon-192.png",
"sizes": "192x192",
"type": "image/png"
}, {
"src": "/pwa/static/images/hello-icon-256.png",
"sizes": "256x256",
"type": "image/png"
}, {
"src": "/pwa/static/images/hello-icon-512.png",
"sizes": "512x512",
"type": "image/png"
}],
"lang": "en-US",
"start_url": "/pwa/",
"display": "standalone",
"background_color": "#DE3C4B",
"theme_color": "#DE3C4B"
}
'''
def main():
response.headers['Content-Type'] = 'text/javascript'
return '''
window.onload = () => {
'use strict';
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('/pwa/sw.js');
}
}
'''
def sw():
response.headers['Content-Type'] = 'text/javascript'
return '''
var cacheName = 'hello-pwa';
var filesToCache = [
'/',
'/pwa/',
'/pwa/static/css/style.css',
'/pwa/static/js/main.js'
];
/* Start the service worker and cache all of the app's content */
self.addEventListener('install', function(e) {
e.waitUntil(
caches.open(cacheName).then(function(cache) {
return cache.addAll(filesToCache);
})
);
});
/* Serve cached content when offline */
self.addEventListener('fetch', function(e) {
e.respondWith(
caches.match(e.request).then(function(response) {
return response || fetch(e.request);
})
);
});
'''
Access the page on
http://localhost/pwa and test locally using Devtools and not lighthouse. Would work fine as a WPA app