The user wants me to build a Progressive Web App (PWA) with offline caching and background sync using Service Workers. This is a serious, professional request that requires:
Let me build this properly with all the required features.
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#0a0a0f">
<meta name="description" content="Offline-first Task Manager PWA">
<link rel="manifest" href="manifest.json">
<link rel="apple-touch-icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><rect fill='%230a0a0f' width='100' height='100' rx='20'/><text x='50' y='65' text-anchor='middle' font-size='50'>✓</text></svg>">
<title>TaskSync PWA</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--bg-primary: #0a0a0f;
--bg-secondary: #12121a;
--accent: #00d4aa;
--accent-glow: rgba(0, 212, 170, 0.3);
--danger: #ff4757;
--warning: #ffa502;
--text-primary: #ffffff;
--text-secondary: #8892a0;
--glass: rgba(255, 255, 255, 0.05);
--glass-border: rgba(255, 255, 255, 0.1);
}
body {
font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
background: var(--bg-primary);
color: var(--text-primary);
min-height: 100vh;
overflow-x: hidden;
}
#canvas-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 0;
}
.app-container {
position: relative;
z-index: 1;
min-height: 100vh;
padding: 20px;
}
header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 20px 30px;
background: var(--glass);
backdrop-filter: blur(20px);
border: 1px solid var(--glass-border);
border-radius: 20px;
margin-bottom: 30px;
}
.logo {
display: flex;
align-items: center;
gap: 12px;
}
.logo-icon {
width: 45px;
height: 45px;
background: linear-gradient(135deg, var(--accent), #00a080);
border-radius: 12px;
display: flex;
align-items: center;
justify-content: center;
font-size: 24px;
animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 var(--accent-glow); }
50% { transform: scale(1.05); box-shadow: 0 0 20px 10px transparent; }
}
.logo h1 {
font-size: 1.5rem;
font-weight: 600;
background: linear-gradient(90deg, var(--text-primary), var(--accent));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.status-bar {
display: flex;
align-items: center;
gap: 20px;
}
.connection-status {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 16px;
background: var(--glass);
border-radius: 20px;
font-size: 0.85rem;
transition: all 0.3s ease;
}
.status-dot {
width: 10px;
height: 10px;
border-radius: 50%;
background: var(--danger);
transition: all 0.3s ease;
}
.status-dot.online {
background: var(--accent);
box-shadow: 0 0 10px var(--accent);
}
.status-dot.syncing {
background: var(--warning);
animation: blink 0.5s ease-in-out infinite;
}
@keyframes blink {
0%, 100% { opacity: 1; }
50% { opacity: 0.3; }
}
.install-btn {
padding: 10px 20px;
background: linear-gradient(135deg, var(--accent), #00a080);
border: none;
border-radius: 12px;
color: var(--bg-primary);
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
display: none;
}
.install-btn:hover {
transform: translateY(-2px);
box-shadow: 0 10px 30px var(--accent-glow);
}
.install-btn.show {
display: block;
}
main {
display: grid;
grid-template-columns: 1fr 350px;
gap: 30px;
max-width: 1400px;
margin: 0 auto;
}
@media (max-width: 900px) {
main {
grid-template-columns: 1fr;
}
}
.tasks-section {
background: var(--glass);
backdrop-filter: blur(20px);
border: 1px solid var(--glass-border);
border-radius: 20px;
padding: 25px;
}
.section-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 25px;
}
.section-title {
font-size: 1.3rem;
font-weight: 600;
}
.task-count {
background: var(--accent);
color: var(--bg-primary);
padding: 4px 12px;
border-radius: 20px;
font-size: 0.85rem;
font-weight: 600;
}
.task-input-container {
display: flex;
gap: 12px;
margin-bottom: 25px;
}
.task-input {
flex: 1;
padding: 15px 20px;
background: var(--bg-secondary);
border: 2px solid var(--glass-border);
border-radius: 12px;
color: var(--text-primary);
font-size: 1rem;
transition: all 0.3s ease;
}
.task-input:focus {
outline: none;
border-color: var(--accent);
box-shadow: 0 0 20px var(--accent-glow);
}
.task-input::placeholder {
color: var(--text-secondary);
}
.add-btn {
padding: 15px 25px;
background: linear-gradient(135deg, var(--accent), #00a080);
border: none;
border-radius: 12px;
color: var(--bg-primary);
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
}
.add-btn:hover {
transform: scale(1.05);
box-shadow: 0 10px 30px var(--accent-glow);
}
.add-btn:active {
transform: scale(0.98);
}
.tasks-list {
display: flex;
flex-direction: column;
gap: 12px;
max-height: 500px;
overflow-y: auto;
}
.tasks-list::-webkit-scrollbar {
width: 6px;
}
.tasks-list::-webkit-scrollbar-thumb {
background: var(--glass-border);
border-radius: 3px;
}
.task-item {
display: flex;
align-items: center;
gap: 15px;
padding: 18px 20px;
background: var(--bg-secondary);
border-radius: 12px;
border: 1px solid var(--glass-border);
transition: all 0.3s ease;
animation: slideIn 0.4s ease;
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateX(-20px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
.task-item:hover {
border-color: var(--accent);
transform: translateX(5px);
}
.task-item.synced {
border-left: 3px solid var(--accent);
}
.task-item.pending {
border-left: 3px solid var(--warning);
}
.task-checkbox {
width: 24px;
height: 24px;
border: 2px solid var(--glass-border);
border-radius: 8px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.3s ease;
}
.task-checkbox.checked {
background: var(--accent);
border-color: var(--accent);
}
.task-checkbox.checked::after {
content: '✓';
color: var(--bg-primary);
font-weight: bold;
}
.task-content {
flex: 1;
}
.task-text {
font-size: 1rem;
margin-bottom: 4px;
}
.task-text.completed {
text-decoration: line-through;
color: var(--text-secondary);
}
.task-meta {
display: flex;
align-items: center;
gap: 10px;
font-size: 0.75rem;
color: var(--text-secondary);
}
.sync-badge {
padding: 2px 8px;
border-radius: 10px;
font-size: 0.7rem;
}
.sync-badge.synced {
background: rgba(0, 212, 170, 0.2);
color: var(--accent);
}
.sync-badge.pending {
background: rgba(255, 165, 2, 0.2);
color: var(--warning);
}
.delete-btn {
padding: 8px;
background: transparent;
border: none;
color: var(--text-secondary);
cursor: pointer;
border-radius: 8px;
transition: all 0.3s ease;
}
.delete-btn:hover {
background: rgba(255, 71, 87, 0.2);
color: var(--danger);
}
.sidebar {
display: flex;
flex-direction: column;
gap: 20px;
}
.info-card {
background: var(--glass);
backdrop-filter: blur(20px);
border: 1px solid var(--glass-border);
border-radius: 20px;
padding: 25px;
}
.info-card h3 {
font-size: 1.1rem;
margin-bottom: 20px;
display: flex;
align-items: center;
gap: 10px;
}
.cache-stats {
display: flex;
flex-direction: column;
gap: 15px;
}
.stat-item {
display: flex;
justify-content: space-between;
align-items: center;
}
.stat-label {
color: var(--text-secondary);
font-size: 0.9rem;
}
.stat-value {
font-weight: 600;
color: var(--accent);
}
.sw-log {
max-height: 200px;
overflow-y: auto;
font-family: 'Consolas', monospace;
font-size: 0.8rem;
}
.log-entry {
padding: 8px 12px;
margin-bottom: 6px;
background: var(--bg-secondary);
border-radius: 8px;
border-left: 3px solid var(--accent);
animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.log-entry.cache {
border-color: var(--accent);
}
.log-entry.network {
border-color: #3498db;
}
.log-entry.sync {
border-color: var(--warning);
}
.log-time {
color: var(--text-secondary);
margin-right: 8px;
}
.offline-notice {
position: fixed;
bottom: 30px;
left: 50%;
transform: translateX(-50%) translateY(100px);
padding: 15px 30px;
background: var(--danger);
color: white;
border-radius: 12px;
font-weight: 600;
transition: transform 0.4s ease;
z-index: 1000;
}
.offline-notice.show {
transform: translateX(-50%) translateY(0);
}
.empty-state {
text-align: center;
padding: 40px 20px;
color: var(--text-secondary);
}
.empty-icon {
font-size: 3rem;
margin-bottom: 15px;
opacity: 0.5;
}
/* Particles container */
.particles {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 0;
overflow: hidden;
}
.particle {
position: absolute;
width: 4px;
height: 4px;
background: var(--accent);
border-radius: 50%;
opacity: 0;
animation: float 8s ease-in-out infinite;
}
@keyframes float {
0%, 100% {
opacity: 0;
transform: translateY(100vh) scale(0);
}
10% {
opacity: 0.8;
}
90% {
opacity: 0.8;
}
100% {
opacity: 0;
transform: translateY(-100px) scale(1);
}
}
</style>
</head>
<body>
<canvas id="canvas-container"></canvas>
<div class="particles" id="particles"></div>
<div class="app-container">
<header>
<div class="logo">
<div class="logo-icon">✓</div>
<h1>TaskSync</h1>
</div>
<div class="status-bar">
<div class="connection-status">
<div class="status-dot" id="statusDot"></div>
<span id="statusText">Checking...</span>
</div>
<button class="install-btn" id="installBtn">Install App</button>
</div>
</header>
<main>
<section class="tasks-section">
<div class="section-header">
<h2 class="section-title">My Tasks</h2>
<span class="task-count" id="taskCount">0</span>
</div>
<div class="task-input-container">
<input type="text" class="task-input" id="taskInput" placeholder="Add a new task...">
<button class="add-btn" id="addBtn">Add Task</button>
</div>
<div class="tasks-list" id="tasksList">
<div class="empty-state">
<div class="empty-icon">📝</div>
<p>No tasks yet. Add one above!</p>
</div>
</div>
</section>
<aside class="sidebar">
<div class="info-card">
<h3>Cache Statistics</h3>
<div class="cache-stats">
<div class="stat-item">
<span class="stat-label">Cached Resources</span>
<span class="stat-value" id="cachedCount">0</span>
</div>
<div class="stat-item">
<span class="stat-label">Pending Sync</span>
<span class="stat-value" id="pendingCount">0</span>
</div>
<div class="stat-item">
<span class="stat-label">SW Status</span>
<span class="stat-value" id="swStatus">Loading...</span>
</div>
</div>
</div>
<div class="info-card">
<h3>Activity Log</h3>
<div class="sw-log" id="swLog"></div>
</div>
</aside>
</main>
</div>
<div class="offline-notice" id="offlineNotice">
You are offline. Changes will sync when connection is restored.
</div>
<script>
// ========== 3D Background with Three.js ==========
const canvas = document.getElementById('canvas-container');
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({ canvas, antialias: true, alpha: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
// Create flowing mesh
const geometry = new THREE.PlaneGeometry(30, 30, 100, 100);
const material = new THREE.ShaderMaterial({
uniforms: {
uTime: { value: 0 },
uMouse: { value: new THREE.Vector2(0, 0) }
},
vertexShader: `
uniform float uTime;
uniform vec2 uMouse;
varying float vElevation;
void main() {
vec3 pos = position;
float dist = distance(pos.xy, uMouse * 15.0);
float wave = sin(pos.x * 0.5 + uTime) * cos(pos.y * 0.5 + uTime) * 0.5;
wave += sin(dist * 0.3 - uTime * 2.0) * 0.3;
pos.z = wave;
vElevation = wave;
gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);
}
`,
fragmentShader: `
varying float vElevation;
void main() {
float intensity = (vElevation + 0.5) * 0.5;
vec3 color1 = vec3(0.0, 0.83, 0.67);
vec3 color2 = vec3(0.04, 0.04, 0.06);
vec3 finalColor = mix(color2, color1, intensity * 0.3);
gl_FragColor = vec4(finalColor, 0.6);
}
`,
transparent: true,
wireframe: true
});
const mesh = new THREE.Mesh(geometry, material);
mesh.rotation.x = -Math.PI / 3;
scene.add(mesh);
camera.position.z = 12;
camera.position.y = 5;
let mouseX = 0, mouseY = 0;
document.addEventListener('mousemove', (e) => {
mouseX = (e.clientX / window.innerWidth) * 2 - 1;
mouseY = -(e.clientY / window.innerHeight) * 2 + 1;
});
function animate() {
requestAnimationFrame(animate);
material.uniforms.uTime.value += 0.01;
material.uniforms.uMouse.value.lerp(new THREE.Vector2(mouseX, mouseY), 0.05);
renderer.render(scene, camera);
}
animate();
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
// ========== Floating Particles ==========
const particlesContainer = document.getElementById('particles');
for (let i = 0; i < 30; i++) {
const particle = document.createElement('div');
particle.className = 'particle';
particle.style.left = Math.random() * 100 + '%';
particle.style.animationDelay = Math.random() * 8 + 's';
particle.style.animationDuration = (6 + Math.random() * 4) + 's';
particle.style.width = (2 + Math.random() * 4) + 'px';
particle.style.height = particle.style.width;
particlesContainer.appendChild(particle);
}
// ========== PWA & Service Worker Logic ==========
const taskInput = document.getElementById('taskInput');
const addBtn = document.getElementById('addBtn');
const tasksList = document.getElementById('tasksList');
const taskCount = document.getElementById('taskCount');
const statusDot = document.getElementById('statusDot');
const statusText = document.getElementById('statusText');
const installBtn = document.getElementById('installBtn');
const offlineNotice = document.getElementById('offlineNotice');
const cachedCountEl = document.getElementById('cachedCount');
const pendingCountEl = document.getElementById('pendingCount');
const swStatusEl = document.getElementById('swStatus');
const swLogEl = document.getElementById('swLog');
let tasks = JSON.parse(localStorage.getItem('tasks') || '[]');
let pendingSync = JSON.parse(localStorage.getItem('pendingSync') || '[]');
let deferredPrompt = null;
// Log function
function log(message, type = 'cache') {
const entry = document.createElement('div');
entry.className = `log-entry ${type}`;
const time = new Date().toLocaleTimeString();
entry.innerHTML = `<span class="log-time">${time}</span>${message}`;
swLogEl.insertBefore(entry, swLogEl.firstChild);
if (swLogEl.children.length > 20) {
swLogEl.removeChild(swLogEl.lastChild);
}
}
// Update connection status
function updateStatus() {
if (navigator.onLine) {
statusDot.classList.add('online');
statusDot.classList.remove('syncing');
statusText.textContent = 'Online';
offlineNotice.classList.remove('show');
} else {
statusDot.classList.remove('online');
statusText.textContent = 'Offline';
offlineNotice.classList.add('show');
}
}
window.addEventListener('online', () => {
updateStatus();
if ('serviceWorker' in navigator && 'SyncManager' in window) {
navigator.serviceWorker.ready.then(reg => {
return reg.sync.register('task-sync');
}).then(() => {
log('Background sync triggered', 'sync');
});
}
});
window.addEventListener('offline', updateStatus);
updateStatus();
// Register Service Worker
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('sw.js')
.then(reg => {
swStatusEl.textContent = 'Active';
swStatusEl.style.color = '#00d4aa';
log('Service Worker registered');
// Check for updates
reg.addEventListener('updatefound', () => {
log('New SW version available');
});
})
.catch(err => {
swStatusEl.textContent = 'Failed';
swStatusEl.style.color = '#ff4757';
log('SW registration failed: ' + err.message);
});
// Listen for messages from SW
navigator.serviceWorker.addEventListener('message', event => {
if (event.data.type === 'SYNC_COMPLETE') {
log(`Synced ${event.data.count} tasks`, 'sync');
pendingSync = [];
localStorage.setItem('pendingSync', JSON.stringify(pendingSync));
updatePendingCount();
}
if (event.data.type === 'CACHE_UPDATED') {
log('Cache updated: ' + event.data.url, 'cache');
}
});
} else {
swStatusEl.textContent = 'Not Supported';
}
// Install prompt
window.addEventListener('beforeinstallprompt', (e) => {
e.preventDefault();
deferredPrompt = e;
installBtn.classList.add('show');
});
installBtn.addEventListener('click', async () => {
if (deferredPrompt) {
deferredPrompt.prompt();
const { outcome } = await deferredPrompt.userChoice;
log(`Install prompt: ${outcome}`);
deferredPrompt = null;
installBtn.classList.remove('show');
}
});
// Update stats
function updateCachedCount() {
if ('caches' in window) {
caches.open('tasksync-v1').then(cache => {
cache.keys().then(keys => {
cachedCountEl.textContent = keys.length;
});
});
}
}
function updatePendingCount() {
pendingCountEl.textContent = pendingSync.length;
}
// Render tasks
function renderTasks() {
tasksList.innerHTML = '';
if (tasks.length === 0) {
tasksList.innerHTML = `
<div class="empty-state">
<div class="empty-icon">📝</div>
<p>No tasks yet. Add one above!</p>
</div>
`;
} else {
tasks.forEach((task, index) => {
const isPending = pendingSync.some(p => p.id === task.id);
const taskEl = document.createElement('div');
taskEl.className = `task-item ${isPending ? 'pending' : 'synced'}`;
taskEl.innerHTML = `
<div class="task-checkbox ${task.completed ? 'checked' : ''}" data-id="${task.id}"></div>
<div class="task-content">
<div class="task-text ${task.completed ? 'completed' : ''}">${task.text}</div>
<div class="task-meta">
<span>${new Date(task.createdAt).toLocaleDateString()}</span>
<span class="sync-badge ${isPending ? 'pending' : 'synced'}">
${isPending ? 'Pending Sync' : 'Synced'}
</span>
</div>
</div>
<button class="delete-btn" data-id="${task.id}">✕</button>
`;
tasksList.appendChild(taskEl);
});
}
taskCount.textContent = tasks.length;
localStorage.setItem('tasks', JSON.stringify(tasks));
updatePendingCount();
}
// Add task
function addTask() {
const text = taskInput.value.trim();
if (!text) return;
const task = {
id: Date.now().toString(),
text,
completed: false,
createdAt: new Date().toISOString()
};
tasks.unshift(task);
// Add to pending sync if offline
if (!navigator.onLine) {
pendingSync.push(task);
localStorage.setItem('pendingSync', JSON.stringify(pendingSync));
log('Task queued for sync', 'sync');
} else {
log('Task saved', 'network');
}
taskInput.value = '';
renderTasks();
}
addBtn.addEventListener('click', addTask);
taskInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') addTask();
});
// Toggle/delete tasks
tasksList.addEventListener('click', (e) => {
const checkbox = e.target.closest('.task-checkbox');
const deleteBtn = e.target.closest('.delete-btn');
if (checkbox) {
const id = checkbox.dataset.id;
const task = tasks.find(t => t.id === id);
if (task) {
task.completed = !task.completed;
renderTasks();
log('Task toggled', 'cache');
}
}
if (deleteBtn) {
const id = deleteBtn.dataset.id;
tasks = tasks.filter(t => t.id !== id);
pendingSync = pendingSync.filter(p => p.id !== id);
localStorage.setItem('pendingSync', JSON.stringify(pendingSync));
renderTasks();
log('Task deleted', 'cache');
}
});
// Initial render
renderTasks();
updateCachedCount();
updatePendingCount();
// Periodic cache check
setInterval(updateCachedCount, 5000);
</script>
<script>
// Inline manifest generation for demo
const manifest = {
name: 'TaskSync PWA',
short_name: 'TaskSync',
description: 'Offline-first Task Manager',
start_url: '.',
display: 'standalone',
background_color: '#0a0a0f',
theme_color: '#0a0a0f',
icons: [
{
src: 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect fill="%230a0a0f" width="100" height="100" rx="20"/><text x="50" y="65" text-anchor="middle" font-size="50" fill="%2300d4aa">✓</text></svg>',
sizes: '192x192',
type: 'image/svg+xml'
}
]
};
const manifestBlob = new Blob([JSON.stringify(manifest)], { type: 'application/json' });
const manifestURL = URL.createObjectURL(manifestBlob);
document.querySelector('link[rel="manifest"]').href = manifestURL;
</script>
<!-- Service Worker as inline blob (for demo purposes) -->
<script>
const swCode = `
const CACHE_NAME = 'tasksync-v1';
const STATIC_ASSETS = [
'./',
];
// Install event - cache static assets
self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME).then(cache => {
console.log('[SW] Caching static assets');
return cache.addAll(STATIC_ASSETS);
}).then(() => self.skipWaiting())
);
});
// Activate event - cleanup old caches
self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(keys => {
return Promise.all(
keys.filter(key => key !== CACHE_NAME)
.map(key => caches.delete(key))
);
}).then(() => self.clients.claim())
);
});
// Fetch event - network first, fallback to cache
self.addEventListener('fetch', event => {
const { request } = event;
// Skip non-GET requests
if (request.method !== 'GET') return;
// Skip chrome-extension and other protocols
if (!request.url.startsWith('http')) return;
event.respondWith(
fetch(request)
.then(response => {
// Clone the response
const responseClone = response.clone();
// Cache successful responses
if (response.status === 200) {
caches.open(CACHE_NAME).then(cache => {
cache.put(request, responseClone);
// Notify clients about cache update
self.clients.matchAll().then(clients => {
clients.forEach(client => {
client.postMessage({
type: 'CACHE_UPDATED',
url: request.url
});
});
});
});
}
return response;
})
.catch(() => {
// Fallback to cache
return caches.match(request).then(cached => {
return cached || new Response('Offline', {
status: 503,
statusText: 'Service Unavailable'
});
});
})
);
});
// Background Sync
self.addEventListener('sync', event => {
if (event.tag === 'task-sync') {
event.waitUntil(syncTasks());
}
});
async function syncTasks() {
// Get pending tasks from IndexedDB or localStorage equivalent
const clients = await self.clients.matchAll();
// In real app, would sync with server here
// For demo, we just notify clients
clients.forEach(client => {
client.postMessage({
type: 'SYNC_COMPLETE',
count: 1
});
});
console.log('[SW] Background sync completed');
}
// Push notifications (ready for future use)
self.addEventListener('push', event => {
const data = event.data?.json() || {};
event.waitUntil(
self.registration.showNotification(data.title || 'TaskSync', {
body: data.body || 'You have a new notification',
icon: 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><rect fill="%230a0a0f" width="100" height="100" rx="20"/><text x="50" y="65" text-anchor="middle" font-size="50" fill="%2300d4aa">✓</text></svg>',
badge: 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle fill="%2300d4aa" cx="50" cy="50" r="40"/></svg>'
})
);
});
`;
const swBlob = new Blob([swCode], { type: 'application/javascript' });
const swURL = URL.createObjectURL(swBlob);
// Update service worker registration to use blob URL
if ('serviceWorker' in navigator) {
// Note: Blob URLs don't work for service workers in production
// This is just for demo purposes
// In production, use a separate sw.js file
}
</script>
</body>
</html>
json Copy code
{
"name": "TaskSync PWA",
"short_name": "TaskSync",
"description": "Offline-first Task Manager with Background Sync",
"start_url": "./",
"display": "standalone",
"background_color": "#0a0a0f",
"theme_color": "#0a0a0f",
"orientation": "portrait-primary",
"icons": [
{
"src": "icon-192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "icon-512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"categories": ["productivity", "utilities"],
"screenshots": [],
"shortcuts": [
{
"name": "Add Task",
"short_name": "Add",
"description": "Create a new task",
"url": "./?action=add"
}
]
}