EJEMPLO WEB APP PWA APLICACION WEB PROGRESIVA HTML CSS JS
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link rel="stylesheet" href="css/styles.css" />
<link rel="manifest" href="/manifest.json" />
<meta name="theme-color" content="#f9d627" />
</head>
<body>
<div class="cba-header">
<img
src="images/beerjs-logo.png"
alt="beerjs-logo"
class="cba-header__logo"
/>
<h1 class="cba-header__title">
BeerJS
<strong>Cba</strong>
</h1>
</div>
<script src="js/main.js"></script>
</body>
</html>
--------------------------------------------------
manifest.json
{
"short_name": "BeerJS",
"name": "BeerJS Cba Web Application",
"icons": [
{
"src": "images/icon-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "images/icon-256x256.png",
"sizes": "256x256",
"type": "image/png"
},
{
"src": "images/icon-384x384.png",
"sizes": "384x384",
"type": "image/png"
},
{
"src": "images/icon-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"start_url": "index.html",
"background_color": "#f9d627",
"display": "standalone",
"scope": "/",
"theme_color": "#f9d627",
"description": "Weather forecast information"
}
-------------------------------------------
sw.js
const STATIC_CACHE = "static-v1";
const APP_SHELL = [
"/",
"index.html",
"css/styles.css",
"js/main.js",
"images/beerjs-logo.png",
];
self.addEventListener("install", (e) => {
const cacheStatic = caches
.open(STATIC_CACHE)
.then((cache) => cache.addAll(APP_SHELL));
e.waitUntil(cacheStatic);
});
self.addEventListener("fetch", (e) => {
console.log("fetch! ", e.request);
e.respondWith(
caches
.match(e.request)
.then((res) => {
return res || fetch(e.request);
})
.catch(console.log)
);
// e.waitUntil(response);
});
----------------------------------
js/main.js
//Configurar SW
let swLocation = "sw.js";
// "/beerjs/sw.js";
if (navigator.serviceWorker) {
if (window.location.href.includes("localhost")) swLocation = "/sw.js"; //Varia según el host
navigator.serviceWorker.register(swLocation);
}
//Logic of web app
console.log("Hello world!!");
------------------------------------------------
/images
Comentarios
Publicar un comentario