Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drawing-app
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hlgr
drawing-app
Commits
06028668
Commit
06028668
authored
5 years ago
by
Nayeem Rahman
Committed by
Nayeem Rahman
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add a service worker, manifest and logo
parent
a905e305
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
public/index.html
+16
-0
16 additions, 0 deletions
public/index.html
public/logo.png
+0
-0
0 additions, 0 deletions
public/logo.png
public/manifest.json
+13
-0
13 additions, 0 deletions
public/manifest.json
public/service-worker.js
+66
-0
66 additions, 0 deletions
public/service-worker.js
with
95 additions
and
0 deletions
public/index.html
+
16
−
0
View file @
06028668
...
...
@@ -2,6 +2,22 @@
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
/>
<link
rel=
"manifest"
href=
"manifest.json"
>
<link
rel=
"shortcut icon"
href=
"logo.png"
>
<script>
if
(
navigator
.
serviceWorker
)
{
navigator
.
serviceWorker
.
register
(
"
service-worker.js
"
)
.
then
(
(
registration
)
=>
console
.
log
(
`Service worker registered on scope
${
registration
.
scope
}
`
,
),
(
reason
)
=>
console
.
log
(
`Service worker failed to register ~
${
reason
}
`
),
)
}
</script>
</head>
<body>
<div>
...
...
This diff is collapsed.
Click to expand it.
public/logo.png
0 → 100644
+
0
−
0
View file @
06028668
2 KiB
This diff is collapsed.
Click to expand it.
public/manifest.json
0 → 100644
+
13
−
0
View file @
06028668
{
"short_name"
:
"Drawing App"
,
"name"
:
"Drawing App"
,
"icons"
:
[
{
"src"
:
"/logo.png"
,
"type"
:
"image/png"
,
"sizes"
:
"144x144"
}
],
"display"
:
"standalone"
,
"start_url"
:
"/index.html"
}
This diff is collapsed.
Click to expand it.
public/service-worker.js
0 → 100644
+
66
−
0
View file @
06028668
self
.
addEventListener
(
"
install
"
,
(
event
)
=>
{
console
.
info
(
"
Service worker installed.
"
,
event
)
})
self
.
addEventListener
(
"
activate
"
,
(
event
)
=>
{
console
.
info
(
"
Service worker activated.
"
,
event
)
})
const
CACHE_NAME
=
"
APP-V0
"
const
FILES_TO_CACHE
=
[
"
/index.html
"
,
"
/js/app.js
"
,
"
/manifest.json
"
,
]
const
FILE_ALIASES
=
new
Map
([
[
"
/
"
,
"
/index.html
"
]
])
const
normalizeUrl
=
(
url
)
=>
{
const
url_
=
new
URL
(
url
)
url_
.
pathname
=
url_
.
pathname
.
replace
(
/
\/
+/g
,
"
/
"
).
replace
(
/
\/
$/
,
""
)
if
(
FILE_ALIASES
.
has
(
url_
.
pathname
))
{
url_
.
pathname
=
FILE_ALIASES
.
get
(
url_
.
pathname
)
}
return
url_
.
href
}
self
.
addEventListener
(
"
install
"
,
async
(
event
)
=>
{
const
cache
=
await
caches
.
open
(
CACHE_NAME
)
const
additions
=
cache
.
addAll
(
FILES_TO_CACHE
)
await
additions
console
.
info
(
`Files cached: [\n
${
FILES_TO_CACHE
.
join
(
`,\n `
)}
\n]`
)
})
self
.
addEventListener
(
"
activate
"
,
async
(
event
)
=>
{
const
oldCacheKeys
=
(
await
caches
.
keys
()).
filter
((
key
)
=>
key
!=
CACHE_NAME
)
oldCacheKeys
.
forEach
((
key
)
=>
caches
.
delete
(
key
))
})
self
.
addEventListener
(
"
fetch
"
,
(
event
)
=>
{
const
normalizedUrl
=
normalizeUrl
(
event
.
request
.
url
)
let
response
=
fetch
(
event
.
request
)
if
(
FILES_TO_CACHE
.
includes
(
normalizedUrl
))
{
response
=
response
.
then
(
async
(
response
)
=>
{
const
cache
=
await
caches
.
open
(
CACHE_NAME
)
await
cache
.
put
(
normalizedUrl
,
response
.
clone
())
return
response
})
.
catch
(()
=>
caches
.
match
(
normalizedUrl
))
.
catch
(
e
=>
null
)
}
event
.
respondWith
(
fetch
(
event
.
request
)
.
then
(
async
(
response
)
=>
{
if
(
FILES_TO_CACHE
.
includes
(
new
URL
(
normalizedUrl
).
pathname
))
{
const
cache
=
await
caches
.
open
(
CACHE_NAME
)
await
cache
.
put
(
normalizedUrl
,
response
.
clone
())
}
return
response
})
.
catch
(()
=>
caches
.
match
(
normalizedUrl
))
.
catch
(
e
=>
null
)
)
})
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment