summaryrefslogtreecommitdiffstats
path: root/templates
diff options
context:
space:
mode:
authorsilverwind <me@silverwind.io>2019-11-21 21:06:23 +0100
committertechknowlogick <techknowlogick@gitea.io>2019-11-21 15:06:23 -0500
commitf0aaffeedccaa7b338af6cf72cef77895513c9f1 (patch)
tree9101b9c92c60a9b9776e1e23fdb9c58ef63f4d38 /templates
parentcbaa1de9ec8ab1baa49357b660fab16a68097c84 (diff)
downloadgitea-f0aaffeedccaa7b338af6cf72cef77895513c9f1.tar.gz
gitea-f0aaffeedccaa7b338af6cf72cef77895513c9f1.zip
Add USE_SERVICE_WORKER setting (#9110)
* Add USE_SERVICE_WORKER setting This will be very useful setting for anyone doing frontend work. Fixes: https://github.com/go-gitea/gitea/issues/9044 * prevent potential syntax error on old browsers
Diffstat (limited to 'templates')
-rw-r--r--templates/base/head.tmpl32
1 files changed, 20 insertions, 12 deletions
diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl
index 32251f84ae..2cc48c632f 100644
--- a/templates/base/head.tmpl
+++ b/templates/base/head.tmpl
@@ -6,22 +6,30 @@
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>{{if .Title}}{{.Title}} - {{end}} {{if .Repository.Name}}{{.Repository.Name}} - {{end}}{{AppName}}</title>
<link rel="manifest" href="{{AppSubUrl}}/manifest.json" crossorigin="use-credentials">
-
+ {{if UseServiceWorker}}
<script>
if ('serviceWorker' in navigator) {
- window.addEventListener('load', function() {
- navigator.serviceWorker.register('{{AppSubUrl}}/serviceworker.js').then(function(registration) {
- // Registration was successful
- console.log('ServiceWorker registration successful with scope: ', registration.scope);
- }, function(err) {
- // registration failed :(
- console.log('ServiceWorker registration failed: ', err);
- });
- });
+ navigator.serviceWorker.register('{{AppSubUrl}}/serviceworker.js').then(function(registration) {
+ // Registration was successful
+ console.info('ServiceWorker registration successful with scope: ', registration.scope);
+ }, function(err) {
+ // registration failed :(
+ console.info('ServiceWorker registration failed: ', err);
+ });
}
-
</script>
-
+ {{else}}
+ <script>
+ if ('serviceWorker' in navigator) {
+ navigator.serviceWorker.getRegistrations().then(function(registrations) {
+ registrations.forEach(function(registration) {
+ registration.unregister();
+ console.info('ServiceWorker unregistered');
+ });
+ });
+ }
+ </script>
+ {{end}}
<meta name="theme-color" content="{{ThemeColorMetaTag}}">
<meta name="author" content="{{if .Repository}}{{.Owner.Name}}{{else}}{{MetaAuthor}}{{end}}" />
<meta name="description" content="{{if .Repository}}{{.Repository.Name}}{{if .Repository.Description}} - {{.Repository.Description}}{{end}}{{else}}{{MetaDescription}}{{end}}" />