pwa: add service worker registration script (#25462)
This commit is contained in:
parent
3eee217291
commit
88baf45c71
|
@ -0,0 +1,10 @@
|
|||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.register('/service-worker.js', {scope: '/'}).then(function(registration) {
|
||||
// Registration was successful
|
||||
console.log('ServiceWorker registration successful with scope: ', registration.scope);
|
||||
swRegistration = registration;
|
||||
}).catch(function(err) {
|
||||
// registration failed :(
|
||||
console.log('ServiceWorker registration failed: ', err);
|
||||
});
|
||||
}
|
|
@ -16,9 +16,14 @@
|
|||
|
||||
from django.conf.urls import url
|
||||
|
||||
from .views import manifest_json, service_worker_js
|
||||
from .views import (
|
||||
manifest_json,
|
||||
service_worker_js,
|
||||
service_worker_registration_js,
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
url('^manifest.json$', manifest_json),
|
||||
url('^service-worker.js$', service_worker_js),
|
||||
url('^service-worker-registration.js$', service_worker_registration_js),
|
||||
]
|
||||
|
|
|
@ -30,3 +30,9 @@ def service_worker_js(request, *args, **kwargs):
|
|||
template = get_template('combo/service-worker.js')
|
||||
return HttpResponse(template.render({}, request),
|
||||
content_type='application/javascript; charset=utf-8')
|
||||
|
||||
|
||||
def service_worker_registration_js(request, *args, **kwargs):
|
||||
template = get_template('combo/service-worker-registration.js')
|
||||
return HttpResponse(template.render({}, request),
|
||||
content_type='application/javascript; charset=utf-8')
|
||||
|
|
Loading…
Reference in New Issue