-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨[feature Request]: Enable PWA for the site (#704)
## Description The website is now a Progressive Web Application where users can install it as a desktop or mobile application and access it easily. Not only that; it also provides offline access by pre-downloading assets mentioned in `service-worker.js` for faster reloading. ## Related Issues - Closes #656 ## Type of PR - [X] (feature Request) ## Screenshots / videos (if applicable) https://www.loom.com/share/635a2d108ff7426a9fb0eb06a61371cc?sid=c520bb83-74c0-4950-8749-5a80a04f3f37 ## Checklist - [X] I have gone through the [contributing guide](https://github.com/Anjaliavv51/Retro) - [X] I have updated my branch and synced it with project `main` branch before making this PR - [X] I have performed a self-review of my code - [X] I have tested the changes thoroughly before submitting this pull request. - [X] I have provided relevant issue numbers, screenshots, and videos after making the changes. - [X] I have commented my code, particularly in hard-to-understand areas. ## Additional context: I have modified `index.html` with an inline comment to link `manifest.json`. I have also added two other files named `manifest.json` and `service-worker.js` for enabling PWA. I have also added a service worker script in `index.html` at the bottom with an inline comment to detect `service-worker.js` file in the root of the folder. I have also resized favicons to 192x192 and 512x512 format for app icon in different screen sizes.
- Loading branch information
Showing
5 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "Retro", | ||
"short_name": "Retro", | ||
"description": "An online platform providing items of vintage collections!", | ||
"start_url": "/index.html", | ||
"display": "standalone", | ||
"background_color": "#F5EBE5", | ||
"theme_color": "#000000", | ||
"icons": [ | ||
{ | ||
"src": "/Favicon image/favicon-192x192.png", | ||
"sizes": "192x192", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "/Favicon image/favicon-512x512.png", | ||
"sizes": "512x512", | ||
"type": "image/png" | ||
} | ||
] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const CACHE_NAME = 'my-pwa-cache-v1'; | ||
const urlsToCache = [ | ||
'/', | ||
'/index.html', | ||
'/style.css', | ||
'/manifest.json', | ||
'/Favicon image/favicon-192x192.png', | ||
'/Favicon image/favicon-512x512.png' | ||
]; | ||
|
||
self.addEventListener('install', (event) => { | ||
event.waitUntil( | ||
caches.open(CACHE_NAME) | ||
.then((cache) => { | ||
return cache.addAll(urlsToCache); | ||
}) | ||
); | ||
}); | ||
|
||
self.addEventListener('fetch', (event) => { | ||
event.respondWith( | ||
caches.match(event.request) | ||
.then((response) => { | ||
return response || fetch(event.request); | ||
}) | ||
); | ||
}); | ||
|
||
self.addEventListener('activate', (event) => { | ||
const cacheWhitelist = [CACHE_NAME]; | ||
event.waitUntil( | ||
caches.keys().then((cacheNames) => { | ||
return Promise.all( | ||
cacheNames.map((cacheName) => { | ||
if (!cacheWhitelist.includes(cacheName)) { | ||
return caches.delete(cacheName); | ||
} | ||
}) | ||
); | ||
}) | ||
); | ||
}); |