Skip to content

Commit

Permalink
Added Progressive Web App Support
Browse files Browse the repository at this point in the history
  • Loading branch information
swarooppatilx committed May 13, 2024
1 parent 980458b commit 6a83587
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
7 changes: 6 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<title>Flipkart</title>
<link rel="icon" type="image/x-icon" href="images/flipkart_lite.png">
<link rel="stylesheet" href="style.css" />
<link rel="manifest" href="manifest.json" />
<link rel="stylesheet" href="./index.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"
Expand Down Expand Up @@ -587,7 +588,11 @@ <h3>ABOUT</h3>
document.getElementById("year").innerHTML = new Date().getFullYear();
</script>


<script>
if('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js', { scope: '/' });
}
</script>

</body>

Expand Down
22 changes: 22 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"background_color": "#ffffff",
"dir": "ltr",
"display": "standalone",
"name": "Flipkart Clone",
"orientation": "any",
"scope": "/",
"short_name": "Flipkart Clone",
"start_url": "/",
"theme_color": "#ffffff",
"icons": [
{
"src": "flipkart_icon.png",
"type": "image/png",
"sizes": "384x384"
},
{
"src": "flipkart_icon.ico",
"type": "image/x-icon"
}
]
}
18 changes: 18 additions & 0 deletions sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This is the "Offline copy of pages" service worker

const CACHE = "flipkart-clone";

importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js');

self.addEventListener("message", (event) => {
if (event.data && event.data.type === "SKIP_WAITING") {
self.skipWaiting();
}
});

workbox.routing.registerRoute(
new RegExp('/*'),
new workbox.strategies.StaleWhileRevalidate({
cacheName: CACHE
})
);

0 comments on commit 6a83587

Please sign in to comment.