Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-Core
Commits
9c251e1a
Verified
Commit
9c251e1a
authored
4 years ago
by
Hangzhi Yu
Committed by
Nik | Klampfradler
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add serviceworker template, settings and file replacement functionality
parent
5daa73f9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!336
Resolve "Review and fix/improve PWA behaviour and serviceworker"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aleksis/core/static/js/serviceworker.js
+7
-19
7 additions, 19 deletions
aleksis/core/static/js/serviceworker.js
aleksis/core/urls.py
+1
-0
1 addition, 0 deletions
aleksis/core/urls.py
with
8 additions
and
19 deletions
aleksis/core/static/js/serviceworker.js
+
7
−
19
View file @
9c251e1a
// This is the AlekSIS service worker
const
CACHE
=
"
aleksis-cache
"
;
const
precacheFiles
=
[
''
,
];
// This is the AlekSIS service worker
const
offlineFallbackPage
=
'
/offlin
e
'
;
const
CACHE
=
'
aleksis-cach
e
'
;
const
avoidCachingPaths
=
[
'
/admin
'
,
'
/settings
'
,
'
/accounts/login
'
];
// TODO: More paths are needed
const
offlineFallbackPage
=
'
offline/
'
;
function
pathComparer
(
requestUrl
,
pathRegEx
)
{
return
requestUrl
.
match
(
new
RegExp
(
pathRegEx
));
...
...
@@ -40,10 +31,7 @@ self.addEventListener("install", function (event) {
event
.
waitUntil
(
caches
.
open
(
CACHE
).
then
(
function
(
cache
)
{
console
.
log
(
"
[AlekSIS PWA] Caching pages during install.
"
);
return
cache
.
addAll
(
precacheFiles
).
then
(
function
()
{
return
cache
.
add
(
offlineFallbackPage
);
});
return
cache
.
addAll
(
precachePaths
);
})
);
});
...
...
@@ -95,11 +83,11 @@ function fromCache(event) {
}
function
updateCache
(
request
,
response
)
{
if
(
!
comparePaths
(
request
.
url
,
avoidCachingPaths
))
{
if
(
response
.
headers
.
get
(
'
cache-control
'
)
&&
response
.
headers
.
get
(
'
cache-control
'
).
includes
(
'
no-cache
'
))
{
return
Promise
.
resolve
();
}
else
{
return
caches
.
open
(
CACHE
).
then
(
function
(
cache
)
{
return
cache
.
put
(
request
,
response
);
});
}
return
Promise
.
resolve
();
}
This diff is collapsed.
Click to expand it.
aleksis/core/urls.py
+
1
−
0
View file @
9c251e1a
...
...
@@ -18,6 +18,7 @@ from .util.core_helpers import is_celery_enabled
urlpatterns
=
[
path
(
""
,
include
(
"
django_prometheus.urls
"
)),
path
(
""
,
include
(
"
pwa.urls
"
),
name
=
"
pwa
"
),
path
(
"
offline/
"
,
views
.
offline
,
name
=
"
offline
"
),
path
(
"
about/
"
,
views
.
about
,
name
=
"
about_aleksis
"
),
path
(
"
admin/
"
,
admin
.
site
.
urls
),
path
(
"
data_management/
"
,
views
.
data_management
,
name
=
"
data_management
"
),
...
...
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