Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
D
django-pwa
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Privacy statement
Keyboard shortcuts
?
What's new
6
Snippets
Groups
Projects
Show more breadcrumbs
Julien Enselme
django-pwa
Commits
7c1211a9
Commit
7c1211a9
authored
5 years ago
by
Julien Enselme
Browse files
Options
Downloads
Patches
Plain Diff
Add ServiceWorker
parent
fdf7519b
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
djangopwa/templates/pwa/my_page.html
+12
-0
12 additions, 0 deletions
djangopwa/templates/pwa/my_page.html
djangopwa/templates/sw.js
+5
-0
5 additions, 0 deletions
djangopwa/templates/sw.js
djangopwa/urls.py
+10
-0
10 additions, 0 deletions
djangopwa/urls.py
with
27 additions
and
0 deletions
djangopwa/templates/pwa/my_page.html
+
12
−
0
View file @
7c1211a9
...
...
@@ -10,5 +10,17 @@
<h1>
A page
</h1>
<p>
This is a very small and uninteresting page of a test site for Django and PWA
</p>
<script>
if
(
'
serviceWorker
'
in
navigator
)
{
navigator
.
serviceWorker
.
register
(
'
{% url "sw.js" %}
'
,
{
scope
:
'
/
'
}).
then
(
function
(
reg
)
{
// registration worked
console
.
log
(
'
Registration succeeded. Scope is
'
+
reg
.
scope
);
}).
catch
(
function
(
error
)
{
// registration failed
console
.
log
(
'
Registration failed with
'
+
error
);
});
}
</script>
</body>
</html>
This diff is collapsed.
Click to expand it.
djangopwa/templates/sw.js
0 → 100644
+
5
−
0
View file @
7c1211a9
const
VERSION
=
'
1.0.0
'
;
self
.
addEventListener
(
'
install
'
,
(
event
)
=>
{
console
.
log
(
'
[SW] Installing SW version:
'
,
VERSION
);
});
This diff is collapsed.
Click to expand it.
djangopwa/urls.py
+
10
−
0
View file @
7c1211a9
...
...
@@ -15,6 +15,7 @@ Including another URLconf
"""
from
django.contrib
import
admin
from
django.urls
import
path
from
django.views.generic
import
TemplateView
from
.apps.pwa
import
views
as
pwa_views
...
...
@@ -24,4 +25,13 @@ urlpatterns = [
path
(
''
,
pwa_views
.
my_page
),
path
(
'
offline/
'
,
pwa_views
.
offline
),
# The service worker cannot be in /static because its scope will be limited to /static.
# Since we want it to have a scope of the full application, we rely on this TemplateView
# trick to make it work.
path
(
'
sw.js
'
,
TemplateView
.
as_view
(
template_name
=
'
sw.js
'
,
content_type
=
'
application/javascript
'
),
name
=
'
sw.js
'
,
),
]
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