-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
106 additions
and
98 deletions.
There are no files selected for viewing
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,18 @@ | ||
{ | ||
"name": "픽토스", | ||
"short_name": "픽토스", | ||
"description": "매일 풀어보는 퀴즈!", | ||
"theme_color": "#ffc211", | ||
"background_color": "#ffffff", | ||
"display": "standalone", | ||
"scope": "/", | ||
"start_url": "/", | ||
"icons": [ | ||
{ | ||
"src": "/assets/logo-192x192.png", | ||
"sizes": "192x192", | ||
"type": "image/png", | ||
"purpose": "any maskable" | ||
} | ||
] | ||
} |
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 |
---|---|---|
@@ -1,101 +1,80 @@ | ||
/** | ||
* Copyright 2018 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
// public/sw.js | ||
import { clientsClaim } from 'workbox-core' | ||
import { precacheAndRoute } from 'workbox-precaching' | ||
import { registerRoute } from 'workbox-routing' | ||
import { NetworkFirst, CacheFirst } from 'workbox-strategies' | ||
import { ExpirationPlugin } from 'workbox-expiration' | ||
import { CacheableResponsePlugin } from 'workbox-cacheable-response' | ||
|
||
// If the loader is already loaded, just stop. | ||
if (!self.define) { | ||
let registry = {}; | ||
clientsClaim() | ||
|
||
// Used for `eval` and `importScripts` where we can't get script URL by other means. | ||
// In both cases, it's safe to use a global var because those functions are synchronous. | ||
let nextDefineUri; | ||
// self.__WB_MANIFEST is injected by workbox-build during the build process | ||
precacheAndRoute(self.__WB_MANIFEST || []) | ||
|
||
const singleRequire = (uri, parentUri) => { | ||
uri = new URL(uri + ".js", parentUri).href; | ||
return registry[uri] || ( | ||
|
||
new Promise(resolve => { | ||
if ("document" in self) { | ||
const script = document.createElement("script"); | ||
script.src = uri; | ||
script.onload = resolve; | ||
document.head.appendChild(script); | ||
} else { | ||
nextDefineUri = uri; | ||
importScripts(uri); | ||
resolve(); | ||
} | ||
}) | ||
|
||
.then(() => { | ||
let promise = registry[uri]; | ||
if (!promise) { | ||
throw new Error(`Module ${uri} didn’t register its module`); | ||
} | ||
return promise; | ||
}) | ||
); | ||
}; | ||
// Cache CSS, JS, and web worker requests with a network-first strategy. | ||
registerRoute( | ||
({ request }) => | ||
request.destination === 'style' || | ||
request.destination === 'script' || | ||
request.destination === 'worker', | ||
new NetworkFirst({ | ||
cacheName: 'static-resources', | ||
}) | ||
) | ||
|
||
// Cache image files with a cache-first strategy. | ||
registerRoute( | ||
({ request }) => request.destination === 'image', | ||
new CacheFirst({ | ||
cacheName: 'images', | ||
plugins: [ | ||
new ExpirationPlugin({ | ||
maxEntries: 50, | ||
}), | ||
], | ||
}) | ||
) | ||
|
||
self.define = (depsNames, factory) => { | ||
const uri = nextDefineUri || ("document" in self ? document.currentScript.src : "") || location.href; | ||
if (registry[uri]) { | ||
// Module is already loading or loaded. | ||
return; | ||
} | ||
let exports = {}; | ||
const require = depUri => singleRequire(depUri, uri); | ||
const specialDeps = { | ||
module: { uri }, | ||
exports, | ||
require | ||
}; | ||
registry[uri] = Promise.all(depsNames.map( | ||
depName => specialDeps[depName] || require(depName) | ||
)).then(deps => { | ||
factory(...deps); | ||
return exports; | ||
}); | ||
}; | ||
} | ||
define(['./workbox-e43f5367'], (function (workbox) { 'use strict'; | ||
// Cache API calls with a network-first strategy. | ||
registerRoute( | ||
({ url }) => url.pathname.startsWith('/api/'), | ||
new NetworkFirst({ | ||
cacheName: 'api', | ||
networkTimeoutSeconds: 10, | ||
plugins: [ | ||
new CacheableResponsePlugin({ | ||
statuses: [0, 200], | ||
}), | ||
], | ||
}) | ||
) | ||
|
||
importScripts(); | ||
self.skipWaiting(); | ||
workbox.clientsClaim(); | ||
workbox.registerRoute("/", new workbox.NetworkFirst({ | ||
"cacheName": "start-url", | ||
plugins: [{ | ||
cacheWillUpdate: async ({ | ||
request, | ||
response, | ||
event, | ||
state | ||
}) => { | ||
if (response && response.type === 'opaqueredirect') { | ||
return new Response(response.body, { | ||
status: 200, | ||
statusText: 'OK', | ||
headers: response.headers | ||
}); | ||
} | ||
return response; | ||
} | ||
}] | ||
}), 'GET'); | ||
workbox.registerRoute(/.*/i, new workbox.NetworkOnly({ | ||
"cacheName": "dev", | ||
plugins: [] | ||
}), 'GET'); | ||
// Cache the start URL with a network-first strategy. | ||
registerRoute( | ||
'/', | ||
new NetworkFirst({ | ||
cacheName: 'start-url', | ||
plugins: [ | ||
{ | ||
cacheWillUpdate: async ({ request, response }) => { | ||
if (response && response.type === 'opaqueredirect') { | ||
return new Response(response.body, { | ||
status: 200, | ||
statusText: 'OK', | ||
headers: response.headers, | ||
}) | ||
} | ||
return response | ||
}, | ||
}, | ||
], | ||
}) | ||
) | ||
|
||
})); | ||
//# sourceMappingURL=sw.js.map | ||
// Cache everything else with a network-only strategy. | ||
registerRoute( | ||
({ request }) => true, | ||
new CacheFirst({ | ||
cacheName: 'catch-all', | ||
}) | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
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,8 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
export const isPWA = (): boolean => { | ||
return ( | ||
window.matchMedia('(display-mode: standalone)').matches || | ||
(window.navigator as any).standalone === true | ||
) | ||
} |
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