Skip to content

Remove the ServiceWorker and manifest.json #12400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ FOMANTIC_DEST_DIR := web_src/fomantic/build
WEBPACK_SOURCES := $(shell find web_src/js web_src/less -type f) $(FOMANTIC_DEST)
WEBPACK_CONFIGS := webpack.config.js
WEBPACK_DEST := public/js/index.js public/css/index.css
WEBPACK_DEST_ENTRIES := public/js public/css public/fonts public/img/webpack public/serviceworker.js
WEBPACK_DEST_ENTRIES := public/js public/css public/fonts public/img/webpack

BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go
BINDATA_HASH := $(addsuffix .hash,$(BINDATA_DEST))
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[简体中文](README_ZH.md)

<h1> <img src="https://raw.githubusercontent.com/go-gitea/gitea/master/public/img/gitea-192.png" alt="logo" width="30" height="30"> Gitea - Git with a cup of tea</h1>
<h1> <img src="https://raw.githubusercontent.com/go-gitea/gitea/master/public/img/favicon.svg" alt="logo" width="30" height="30"> Gitea - Git with a cup of tea</h1>

[![Build Status](https://drone.gitea.io/api/badges/go-gitea/gitea/status.svg?ref=refs/heads/master)](https://drone.gitea.io/go-gitea/gitea)
[![Join the Discord chat at https://discord.gg/Gitea](https://img.shields.io/discord/322538954119184384.svg)](https://discord.gg/Gitea)
Expand Down
2 changes: 1 addition & 1 deletion README_ZH.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[English](README.md)

<h1> <img src="https://raw.githubusercontent.com/go-gitea/gitea/master/public/img/gitea-192.png" alt="logo" width="30" height="30"> Gitea - Git with a cup of tea</h1>
<h1> <img src="https://raw.githubusercontent.com/go-gitea/gitea/master/public/img/favicon.svg" alt="logo" width="30" height="30"> Gitea - Git with a cup of tea</h1>

[![Build Status](https://drone.gitea.io/api/badges/go-gitea/gitea/status.svg)](https://drone.gitea.io/go-gitea/gitea)
[![Join the Discord chat at https://discord.gg/Gitea](https://img.shields.io/discord/322538954119184384.svg)](https://discord.gg/Gitea)
Expand Down
2 changes: 0 additions & 2 deletions build/generate-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ async function main() {
const svg = await readFile(resolve(__dirname, '../assets/logo.svg'), 'utf8');
await generateSvgFavicon(svg, resolve(__dirname, '../public/img/favicon.svg'));
await generate(svg, resolve(__dirname, '../public/img/gitea-lg.png'), {size: 880});
await generate(svg, resolve(__dirname, '../public/img/gitea-512.png'), {size: 512});
await generate(svg, resolve(__dirname, '../public/img/gitea-192.png'), {size: 192});
await generate(svg, resolve(__dirname, '../public/img/gitea-sm.png'), {size: 120});
await generate(svg, resolve(__dirname, '../public/img/avatar_default.png'), {size: 200});
await generate(svg, resolve(__dirname, '../public/img/favicon.png'), {size: 180, removeDetail: true});
Expand Down
2 changes: 0 additions & 2 deletions custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ REACTIONS = +1, -1, laugh, hooray, confused, heart, rocket, eyes
DEFAULT_SHOW_FULL_NAME = false
; Whether to search within description at repository search on explore page.
SEARCH_REPO_DESCRIPTION = true
; Whether to enable a Service Worker to cache frontend assets
USE_SERVICE_WORKER = true

[ui.admin]
; Number of users that are displayed on one page
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 @@ -137,7 +137,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 @@ -151,8 +151,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 and adding SVGs

SVG icons are built using the `make svg` target which compiles the icon sources defined in `build/generate-svg.js` into the output directory `public/img/svg`. Custom icons can be added in the `web_src/svg` directory.
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 @@ -1012,7 +1011,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 @@ -169,9 +169,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
22 changes: 0 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
"webpack": "4.44.0",
"webpack-cli": "3.3.12",
"webpack-fix-style-only-entries": "0.5.1",
"workbox-routing": "5.1.3",
"workbox-strategies": "5.1.3",
"worker-loader": "2.0.0",
"wrap-ansi": "7.0.0"
},
Expand Down
Binary file removed public/img/gitea-512.png
Binary file not shown.
5 changes: 0 additions & 5 deletions routers/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1043,11 +1043,6 @@ func RegisterRoutes(m *macaron.Macaron) {
ctx.Redirect(path.Join(setting.StaticURLPrefix, "img/apple-touch-icon.png"), 301)
})

// Progressive Web App
m.Get("/manifest.json", templates.JSONRenderer(), func(ctx *context.Context) {
ctx.HTML(200, "pwa/manifest_json")
})

// prometheus metrics endpoint
if setting.Metrics.Enabled {
c := metrics.NewCollector()
Expand Down
2 changes: 0 additions & 2 deletions templates/base/head.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<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">
<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 All @@ -30,7 +29,6 @@
AppVer: '{{AppVer}}',
AppSubUrl: '{{AppSubUrl}}',
StaticUrlPrefix: '{{StaticUrlPrefix}}',
UseServiceWorker: {{UseServiceWorker}},
csrf: '{{.CsrfToken}}',
HighlightJS: {{if .RequireHighlightJS}}true{{else}}false{{end}},
SimpleMDE: {{if .RequireSimpleMDE}}true{{else}}false{{end}},
Expand Down
31 changes: 0 additions & 31 deletions templates/pwa/manifest_json.tmpl

This file was deleted.

46 changes: 8 additions & 38 deletions web_src/js/features/serviceworker.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,23 @@
const {UseServiceWorker, AppSubUrl, AppVer} = window.config;
const cachePrefix = 'static-cache-v'; // actual version is set in the service worker script

async function unregister() {
if (!('serviceWorker' in navigator)) return;
const registrations = await navigator.serviceWorker.getRegistrations();
await Promise.all(registrations.map((registration) => {
return registration.active && registration.unregister();
}));
}

async function invalidateCache() {
if (!caches || !caches.keys) return;
const cacheKeys = await caches.keys();
await Promise.all(cacheKeys.map((key) => {
return key.startsWith(cachePrefix) && caches.delete(key);
return key.startsWith('static-cache-v') && caches.delete(key);
}));
}

async function checkCacheValidity() {
const cacheKey = AppVer;
const storedCacheKey = localStorage.getItem('staticCacheKey');

// invalidate cache if it belongs to a different gitea version
if (cacheKey && storedCacheKey !== cacheKey) {
await invalidateCache();
localStorage.setItem('staticCacheKey', cacheKey);
}
}

export default async function initServiceWorker() {
if (!('serviceWorker' in navigator)) return;

if (UseServiceWorker) {
try {
// normally we'd serve the service worker as a static asset from StaticUrlPrefix but
// the spec strictly requires it to be same-origin so it has to be AppSubUrl to work
await Promise.all([
checkCacheValidity(),
navigator.serviceWorker.register(`${AppSubUrl}/serviceworker.js`),
]);
} catch (err) {
console.error(err);
await Promise.all([
invalidateCache(),
unregister(),
]);
}
} else {
await Promise.all([
invalidateCache(),
unregister(),
]);
}
// we once had a service worker, if it's present, remove it and wipe its cache
await Promise.all([
invalidateCache(),
unregister(),
]);
}
23 changes: 0 additions & 23 deletions web_src/js/serviceworker.js

This file was deleted.

9 changes: 1 addition & 8 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ module.exports = {
swagger: [
resolve(__dirname, 'web_src/js/standalone/swagger.js'),
],
serviceworker: [
resolve(__dirname, 'web_src/js/serviceworker.js'),
],
'eventsource.sharedworker': [
resolve(__dirname, 'web_src/js/features/eventsource.sharedworker.js'),
],
Expand All @@ -61,11 +58,7 @@ module.exports = {
devtool: false,
output: {
path: resolve(__dirname, 'public'),
filename: ({chunk}) => {
// serviceworker can only manage assets below it's script's directory so
// we have to put it in / instead of /js/
return chunk.name === 'serviceworker' ? '[name].js' : 'js/[name].js';
},
filename: 'js/[name].js',
chunkFilename: 'js/[name].js',
},
optimization: {
Expand Down