Skip to content

Commit

Permalink
Remove the service worker and ui.USE_SERVICE_WORKER option
Browse files Browse the repository at this point in the history
We don't really gain anything from it except the client-side caching
which is a problem better solved on HTTP level. Gitea is not a PWA and
will not do anything useful in a offline scenario without having access
to the server.

This should also resolve issues seen with the serviceworker interfering
on SSE requests.

The only API we can not use without a service worker is push
notifications while the "app" is closed but the more established
HTML Notification API will be a alternative.

Fixes: go-gitea#11092
Fixes: go-gitea#8056
Fixes: go-gitea#7372
  • Loading branch information
silverwind committed May 20, 2020
1 parent c7c6177 commit b98948d
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 119 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ rules:
no-cond-assign: [2, except-parens]
no-console: [1, {allow: [info, warn, error]}]
no-continue: [0]
no-empty: [2, {allowEmptyCatch: true}]
no-eq-null: [2]
no-mixed-operators: [0]
no-multi-assign: [0]
Expand Down
1 change: 0 additions & 1 deletion docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
For custom reactions, add a tightly cropped square image to public/emoji/img/reaction_name.png
- `DEFAULT_SHOW_FULL_NAME`: **false**: Whether the full name of the users should be shown where possible. If the full name isn't set, the username will be used.
- `SEARCH_REPO_DESCRIPTION`: **true**: Whether to search within description at repository search on explore page.
- `USE_SERVICE_WORKER`: **true**: Whether to enable a Service Worker to cache frontend assets.

### UI - Admin (`ui.admin`)

Expand Down
2 changes: 0 additions & 2 deletions docs/content/doc/advanced/hacking-on-gitea.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ Before committing, make sure the linters pass:
make lint-frontend
```

Note: When working on frontend code, set `USE_SERVICE_WORKER` to `false` in `app.ini` to prevent undesirable caching of frontend assets.

### Building Images

To build the images, ImageMagick, `inkscape` and `zopflipng` binaries must be available in
Expand Down
2 changes: 0 additions & 2 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ var (
Reactions []string
ReactionsMap map[string]bool
SearchRepoDescription bool
UseServiceWorker bool

Notification struct {
MinTimeout time.Duration
Expand Down Expand Up @@ -1018,7 +1017,6 @@ func NewContext() {
UI.ShowUserEmail = Cfg.Section("ui").Key("SHOW_USER_EMAIL").MustBool(true)
UI.DefaultShowFullName = Cfg.Section("ui").Key("DEFAULT_SHOW_FULL_NAME").MustBool(false)
UI.SearchRepoDescription = Cfg.Section("ui").Key("SEARCH_REPO_DESCRIPTION").MustBool(true)
UI.UseServiceWorker = Cfg.Section("ui").Key("USE_SERVICE_WORKER").MustBool(true)

HasRobotsTxt = com.IsFile(path.Join(CustomPath, "robots.txt"))

Expand Down
3 changes: 0 additions & 3 deletions modules/templates/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,6 @@ func NewFuncMap() []template.FuncMap {
"MetaKeywords": func() string {
return setting.UI.Meta.Keywords
},
"UseServiceWorker": func() bool {
return setting.UI.UseServiceWorker
},
"FilenameIsImage": func(filename string) bool {
mimeType := mime.TypeByExtension(filepath.Ext(filename))
return strings.HasPrefix(mimeType, "image/")
Expand Down
4 changes: 0 additions & 4 deletions routers/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1048,10 +1048,6 @@ func RegisterRoutes(m *macaron.Macaron) {
ctx.HTML(200, "pwa/manifest_json")
})

m.Get("/serviceworker.js", templates.JSRenderer(), func(ctx *context.Context) {
ctx.HTML(200, "pwa/serviceworker_js")
})

// prometheus metrics endpoint
if setting.Metrics.Enabled {
c := metrics.NewCollector()
Expand Down
24 changes: 0 additions & 24 deletions templates/base/head.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,6 @@
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>{{if .Title}}{{.Title | RenderEmojiPlain}} - {{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) {
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}}" />
Expand Down
83 changes: 0 additions & 83 deletions templates/pwa/serviceworker_js.tmpl

This file was deleted.

11 changes: 11 additions & 0 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3594,3 +3594,14 @@ $.get(`${window.config.StaticUrlPrefix}/img/svg/icons.svg`, (data) => {
div.innerHTML = new XMLSerializer().serializeToString(data.documentElement);
document.body.insertBefore(div, document.body.childNodes[0]);
});

// remove any previously installed serviceworkers
if ('serviceWorker' in navigator) {
try {
navigator.serviceWorker.getRegistrations().then((registrations) => {
for (const registration of registrations) {
registration.unregister();
}
});
} catch (_err) {}
}

0 comments on commit b98948d

Please sign in to comment.