PWA(Progressive Web App)는 웹 기술을 활용하여 네이티브 앱과 유사한 사용자 경험을 제공하는 웹 애플리케이션입니다. PWA는 오프라인에서도 작동할 수 있으며, 푸시 알림을 지원하고, 홈 화면에 추가하여 앱처럼 실행할 수 있습니다.
서비스 워커는 PWA에서 가장 중요한 요소로, 캐싱 및 오프라인 기능을 담당합니다.
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/service-worker.js')
.then(registration => {
console.log('Service Worker 등록 성공:', registration);
})
.catch(error => {
console.log('Service Worker 등록 실패:', error);
});
});
}
service-worker.js
)const CACHE_NAME = 'pwa-cache-v1';
const urlsToCache = [
'/',
'/index.html',
'/styles.css',
'/script.js'
];
self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME)
.then(cache => {
console.log('캐시 저장 완료');
return cache.addAll(urlsToCache);
})
);
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(response => {
return response || fetch(event.request);
})
);
});
manifest.json
) 작성웹 앱 매니페스트는 PWA가 네이티브 앱처럼 동작할 수 있도록 도와줍니다.
{
"name": "My PWA App",
"short_name": "PWA App",
"start_url": "/index.html",
"display": "standalone",
"background_color": "#ffffff",
"theme_color": "#000000",
"icons": [
{
"src": "icon.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "icon-large.png",
"sizes": "512x512",
"type": "image/png"
}
]
}
<head>
<link rel="manifest" href="/manifest.json">
</head>
F12
또는 Ctrl + Shift + I
를 눌러 개발자 도구 열기Lighthouse
탭에서 PWA 항목 분석 및 개선점 확인설치
버튼이 보이면 정상적으로 동작하는 것!✅ 네이티브 앱 설치 없이 앱과 같은 경험 제공
✅ 오프라인에서도 콘텐츠 이용 가능
✅ 푸시 알림으로 사용자 재방문 유도
✅ 크로스 플랫폼 지원 (iOS, Android, 데스크톱)
PWA는 웹과 네이티브 앱의 장점을 결합한 혁신적인 기술입니다. 적절한 캐싱, 푸시 알림, 서비스 워커 활용을 통해 빠르고 강력한 웹 애플리케이션을 만들 수 있습니다. 웹사이트에 PWA를 적용하여 사용자의 경험을 더욱 향상시켜 보세요! 🚀
Progressive Web Apps combine the best features of web and mobile applications, offering offline access, fast performance, and app-like user experiences. Understanding what is PWA app is essential for building modern, engaging applications.
For a comprehensive guide and practical insights, check out: what is PWA app.