Categories

manifest.json
file that provides metadata about your application. This file should include essential information such as:short_name
and name
icons
(various sizes)start_url
background_color
display
(standalone, fullscreen, or minimal-ui)theme_color
manifest.json
file:{
"short_name": "DataGifting",
"name": "DataGifting",
"icons": [
{
"src": "/icon-192x192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "/icon-512x512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": "/web",
"background_color": "#fff",
"display": "standalone",
"theme_color": "#3f51b5"
}
sw.js
file and register it in your website’s JavaScript code:if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js')
.then((registration) => {
console.log('Service worker registered successfully');
})
.catch((error) => {
console.error('Service worker registration failed:', error);
});
}
<button id="install-pwa-button">Install DataGifting</button>
let deferredInstallPrompt = null;
const installButton = document.getElementById('install-pwa-button');
window.addEventListener('beforeinstallprompt', (event) => {
event.preventDefault();
deferredInstallPrompt = event;
installButton.style.display = 'block';
});
installButton.addEventListener('click', async () => {
if (deferredInstallPrompt) {
deferredInstallPrompt.prompt();
const { outcome } = await deferredInstallPrompt.userChoice;
console.log('User choice outcome:', outcome);
}
});