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

Improve asset handling to allow including multiple files #362

Closed
LukasKalbertodt opened this issue Mar 14, 2022 · 0 comments · Fixed by #1167
Closed

Improve asset handling to allow including multiple files #362

LukasKalbertodt opened this issue Mar 14, 2022 · 0 comments · Fixed by #1167
Assignees
Labels
area:backend Everything backend related area:http-server HTTP server of the backend kind:improvement priority:high High priority

Comments

@LukasKalbertodt
Copy link
Member

LukasKalbertodt commented Mar 14, 2022

For custom fonts and code splitting, we need to improve the way we handle assets. Currently, it's not possible to include a full folder of files, which needs to change. Also, there are a few ugly parts of the way we do assets right now. Hopefully we can clean this up a bit.

For this, reinda needs to be changed.

Random notes:

  • The frontend config we have right now is a bit annoying because we have manual JSON in index.html. We need this for the path template thingy. It would be nice to be able to get a path of a file programmatically outside of the template.
  • We also likely want to move the logos and config from backend to somewhere else in the repo.
@LukasKalbertodt LukasKalbertodt added area:http-server HTTP server of the backend area:backend Everything backend related kind:improvement priority:high High priority labels Mar 14, 2022
@LukasKalbertodt LukasKalbertodt self-assigned this Mar 14, 2022
@LukasKalbertodt LukasKalbertodt moved this to Todo in Tobira Mar 14, 2022
owi92 added a commit that referenced this issue May 15, 2024
… bundle splitting (#1167)

Fixes #287 
Fixes #362
First steps towards #257 

<details>
<summary>Historical background pretty irrelevant for users of
Tobira</summary>

This was on my radar for years already, and we always talked about
making fonts configurable and splitting the frontend. Both were blocked
by us using `reinda` as a library to manage assets, which had some
limitations (mainly: not being able to include wildcards). I tried
tackling this a couple of time, but never succeeded. This time I wanted
to finally make it work, since we needed configurable fonts.

And boy, it was a lot more complex than I thought. This seems very
simple on the surface but the complexity comes from the two different
modes: in release mode we want to embed most assets into the executable,
but in debug mode we want to load everything dynamically for faster
development speed. Neither of these things are really up for debate.
Combine that with the need to have hashes in file names, which means
that references to assets need to be fixed, and you have a very complex
system. I'm convinced this would have been at most marginally easier
when doing that all inside Tobira, instead of having that logic live in
an external library. So yeah, as far as I see this was just a hard task.
I am probably only writing this here so that I don't feel so bad for
taking such a long time 😭

Anyway, I am happy with the result, both the library and how it works in
Tobira. It also gets rid of this terrible frontend config mess we had
before. Now it's mostly just one `json!{}` call and easy to read.

</details>

The user/admin-facing change in this PR is configurable font. Admins can
specify a font-family, custom CSS (with `@font-face` declarations) and a
list of font files in the config. The font files are served as static
files, the CSS and font-family is included. This should be plenty
flexible! The default Open Sans font is still always included, I don't
think that hurts.

See the changes in `config.toml` for more information.


![image](https://github.com/elan-ev/tobira/assets/7419664/8b33f5ab-1831-4ea0-b0b7-8da917797275)

---

The other change, which is only indirectly user-facing is that I started
code splitting. This was just to verify it's possible with the new
`reinda`, it's absolutely not perfect yet. I just split the biggest
dependency in our bundle (Paella) into its own file. This reduces the JS
size required to render the main site considerably (3.0MB -> 1.3MB).

Since the new reinda also uses `brotli` instead of `flate2`, the Tobira
binary size might have shrunk a bit. EDIT: nope, not considerably:
34.8MB -> 34.6MB. For the record: size of embedded assets is 2.4MiB in
total (13.9MiB when uncompressed).

Finally: `reinda` is not yet released. I wanted to wait for this PR to
get reviewed before doing that. Once I get a thumbs up, I will release
reinda, adjust `Cargo.toml` and then this PR can be merged.

(PR can be reviewed commit by commit)
@github-project-automation github-project-automation bot moved this from Todo to Done ✔️ in Tobira May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:backend Everything backend related area:http-server HTTP server of the backend kind:improvement priority:high High priority
Projects
Status: Done ✔️
1 participant