Skip to content
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

Inline manifest.json #14038

Merged
merged 10 commits into from
Dec 22, 2020
Merged

Inline manifest.json #14038

merged 10 commits into from
Dec 22, 2020

Conversation

silverwind
Copy link
Member

@silverwind silverwind commented Dec 17, 2020

Improve performance by eliminating this separate request and just inline this small JSON in HTML directly as a data uri. Also, I've updated the previously static app name scripts to use AppName from config. theme_color is removed because it's duplicating with the existing meta tag.

I've confirmed this as working via "Add to Homescreen" feature which offered to save the shortcut under the new app name.

@silverwind silverwind added type/refactoring Existing code has been cleaned up. There should be no new functionality. performance/speed performance issues with slow downs type/enhancement An improvement of existing functionality and removed type/refactoring Existing code has been cleaned up. There should be no new functionality. labels Dec 17, 2020
@silverwind silverwind added this to the 1.14.0 milestone Dec 17, 2020
@zeripath
Copy link
Contributor

Is the data uri always going to work?

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 17, 2020
@silverwind
Copy link
Member Author

silverwind commented Dec 17, 2020

Yes, browsers are required to implement data URIs if they want to conform HTML5.

We just need to be careful with data emitted in the string because it must be URL-escaped. I guess StaticUrlPrefix and AppSubUrl should generally only contain URL-safe characters but I guess we could also just escape them.

@silverwind
Copy link
Member Author

Okay everything is escaped now including the URLs. Browsers will URL-decode the string before parsing it is it's safe to do in all cases.

main.go Outdated
@@ -41,7 +40,6 @@ var (
func init() {
setting.AppVer = Version
setting.AppBuiltWith = formatBuiltWith()
setting.AppStartTime = time.Now().UTC()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems unrelated, could you describe why this is being removed?

Copy link
Member Author

@silverwind silverwind Dec 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I's becoming unused because the /manifest.json route was the only consumer of the variable (I added it with the HTTP cache commit). We can keep it around if you prefer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think it's duplicate with this line also.

startTime = time.Now()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've restored setting.AppStartTime and it's now being used on the admin page:

image

@zeripath
Copy link
Contributor

Is it possible keep the file but insert its contents directly into the attribute?

That way you can keep the endpoint around for those who don't update their templates

@silverwind
Copy link
Member Author

silverwind commented Dec 17, 2020

Can't insert the JSON as-is because it needs URL escaping and I'm generally leaning to not do that kind of extra processing for the sake of performance.

What is the issue exactly about people not updating their templates? I thought templates work by the way of inserting user content at strategic places in the HTML. How come a user would have these parts hardcoded in their template customization?

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Dec 18, 2020
@lunny
Copy link
Member

lunny commented Dec 18, 2020

It could be put in bindata and load on template rendering if necessary.

@silverwind
Copy link
Member Author

I was thinking about generating it once on app startup and caching it in memory for even more speed, thought I guess the gains would be minimal.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Dec 19, 2020
@lunny
Copy link
Member

lunny commented Dec 19, 2020

Please resolve the conflicts.

Improve performance by eliminating this separate request and just inline
this small JSON in HTML directly as a data uri.

Also update previously static app name scripts to use AppName.

I've confirmed this as working via "Add to Homescreen" feature which
offered to save the shortcut under the new app name.
modules/templates/helper.go Outdated Show resolved Hide resolved
@wULLSnpAXbWZGYDYyhWTKKspEQoaYxXyhoisqHf
Copy link
Contributor

What is the issue exactly about people not updating their templates? I thought templates work by the way of inserting user content at strategic places in the HTML. How come a user would have these parts hardcoded in their template customization?

I am keeping around a custom template.
What exactly would I have to update in my pwa/manifest_json.tmpl to make it work once this is merged?
From what I gathered I should be ok :D

@silverwind
Copy link
Member Author

Ah, so you are customizing the "private" templates, didn't know that was possible.

You can just delete it, it doesn't exist anymore after this change.

@wULLSnpAXbWZGYDYyhWTKKspEQoaYxXyhoisqHf
Copy link
Contributor

Ah, so you are customizing the "private" templates, didn't know that was possible.

You can just delete it, it doesn't exist anymore after this change.

well that's too bad because I'm doing a little customization in there, such as using relative /img references.

@lunny
Copy link
Member

lunny commented Dec 22, 2020

Ah, so you are customizing the "private" templates, didn't know that was possible.
You can just delete it, it doesn't exist anymore after this change.

well that's too bad because I'm doing a little customization in there, such as using relative /img references.

I think you could find other way to do that on Gitea.

@lunny lunny added the pr/breaking Merging this PR means builds will break. Needs a description what exactly breaks, and how to fix it! label Dec 22, 2020
@lunny lunny merged commit 3a21f8a into go-gitea:master Dec 22, 2020
@silverwind silverwind deleted the manifestinline branch December 22, 2020 11:16
@wULLSnpAXbWZGYDYyhWTKKspEQoaYxXyhoisqHf
Copy link
Contributor

Ah, so you are customizing the "private" templates, didn't know that was possible.
You can just delete it, it doesn't exist anymore after this change.

well that's too bad because I'm doing a little customization in there, such as using relative /img references.

I think you could find other way to do that on Gitea.

yeah, the expression will have to be replaced on the proxy.

@go-gitea go-gitea locked and limited conversation to collaborators Feb 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. performance/speed performance issues with slow downs pr/breaking Merging this PR means builds will break. Needs a description what exactly breaks, and how to fix it! type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants