-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Migrate from bindata to go:embed #22887
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
Conversation
See also #17352. |
@delvh It uses go:embed statements and then references those in other packages. The only thing not addressed is Accept-Encoding compression. The assets in go:embed are not compressed, so I dropped the Accept-Encoding check. However as mentioned in #17352 it could be added back by adding https://github.com/vearutop/statigz |
b769a8b
to
8685a95
Compare
I haven't looked into details about all changes. But for
Just my opinion. |
This embeds uncompressed assets so binary size will go up by a few tens of MBs after this. I'm not against landing uncompressed now and doing compression later as having |
Sorry, I think we need a better resolution to replace the old system. |
Then let's add I guess https://github.com/webpack-contrib/compression-webpack-plugin#using-brotli would be ideal. For options, you can use params: {
[constants.BROTLI_PARAM_MODE]: constants.BROTLI_MODE_TEXT,
[constants.BROTLI_PARAM_QUALITY]: constants.BROTLI_MAX_QUALITY,
} |
Question is thought whether want to still support serving uncompressed assets or if browser brotli support can be made a requirement. If we want to serve uncompressed with only brotli embedded, it would require a CGO dependency to decompress at runtime, which I think we should not take. Otherwise we could do gzip like vfsgen, but that is a suboptimal solution in terms of both binary size and web performance. Or maybe even embed both gzip and brotli at the same time. |
Actually https://github.com/andybalholm/brotli might work for a pure golang brotli decoder, avoiding CGO. |
I think we may not actually need
Depending on how long these decompressions take, it might be good to keep the results in a memory cache, but I imagine it may be fast enough. |
Sounds good. The last requirement is developers don't want compress when it's in dev mode I think. |
Yes, disable the webpack plugin in development. Development should not use go:embed, but instead use the assets from the filesystem that webpack continously outputs, e.g. same behaviour as now with the |
go:embed is part of the standard library and does not require an extra go:generate step. Migrate all usages of bindata to go:embed. Make embedded the new default (previously required bindata tag). Add new tag "servedynamic" which serves from filesystem (old !bindata). Accept-Encoding compression has been dropped. The assets in go:embed are not available in a compressed form. The compression could be enabled again by adding a compress middleware: https://github.com/vearutop/statigz Drop vfsgen dependency (no longer required). Fixes go-gitea#17352 Signed-off-by: Christian Stewart <[email protected]>
Sorry for bothering, is this PR active? It seems there is no progress for some review comments. |
It's active insofar I'm still interested in merging it, but there were a number of comments around wanting to use compression for the assets and I'm not really in a position to implement that right now, so if someone else will have to edit the PR for that. |
Thank you very much for your contribution. Since we have a refactoring PR for "custom/static/builtin" assets, there are a lot of conflicts. So at the moment I can see some possible decisions for this PR:
What do you think about it? |
I'd merge this even without compression, but some numbers of binary size before and after would be good, so we can judge the impact of missing compression. It's an important step to get this done as it simplifies the build a lot. I can collaborate adding at least the compressed from webpack side. |
I'll have a look at adjusting this PR to use the bindata tag and resolve conflicts Edit: I'm quite busy at the moment so it might take a while for me to get around to this, sorry |
I cannot see it's necessary to merge without compressing. It's a regression for end-user usage. What is the problem of the old embed method for the end user? |
You're right, it is a regression for the end user if we don't handle compression. Right now they get gzip assets when the browser indicates it in accept-encoding. So I guess let's get this branch up to date and then we can potentially collaborate on it to add compression back. For me, it's mostly about the simplification of the build, so it's better development experience. |
brotli is only good for text based files. Anything binary like png's is better compressed using gzip. |
|
Brotli has non-text modes as well, but we don't really need to dive into it so deeply. I would compress those anyways for simplicity's sake in the first iteration of this as the difference will be neglible and it simplifies the implementation. |
I've added support for generic and font broti modes in precompress. I think I will also implement a feature to it to take assets from one directory and output compressed ones into another directory with subfolders intact. I guess such an option would be easiest for gitea to implement so we can leave the |
Stale and it seems that nobody is interested in this change? |
We need compression before we can merge this, gzip is fine, brotli even better. |
If there is no progress ..... there seems no other choice besides close it (also due to the conflicts) |
To summarize the situation:
https://github.com/thealetheia/broccoli seems to take care of point 1 but seems unmaintained. Point 2 can not be resolved without |
A better solution: Use go:embed with server-side gzip support #26533 |
Stale. Free free to reopen if some comments like #22887 (comment) are addressed. |
Migrate from bindata to go:embed
go:embed is part of the standard library and does not require an extra
go:generate step.
Migrate all usages of bindata to go:embed.
Make embedded the new default (previously required bindata tag).
Add new tag "servedynamic" which serves from filesystem (old !bindata).
Accept-Encoding compression has been dropped. The assets in go:embed are not
available in a compressed form. The compression could be enabled again by adding
a compress middleware: https://github.com/vearutop/statigz
Fixes #17352.