// index.php PHP PWA Demo
คุณกำลังอยู่ในโหมดออฟไลน์

PHP PWA Demo

ยินดีต้อนรับสู่ PWA

นี่คือตัวอย่าง Progressive Web App ที่สร้างด้วย PHP

// manifest.json { "name": "PHP PWA Demo", "short_name": "PHP PWA", "start_url": "/index.php", "display": "standalone", "background_color": "#ffffff", "theme_color": "#2196F3", "icons": [ { "src": "icons/icon-192x192.png", "sizes": "192x192", "type": "image/png", "purpose": "any maskable" }, { "src": "icons/icon-512x512.png", "sizes": "512x512", "type": "image/png", "purpose": "any maskable" } ] } // service-worker.js const CACHE_NAME = 'pwa-cache-v1'; const urlsToCache = [ '/', '/index.php', '/manifest.json', '/icons/icon-192x192.png', '/icons/icon-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 => { if (response) { return response; } return 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); } }) ); }) ); });