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

Serve precompressed *.gz file #53

Open
Tracked by #54
Eason0729 opened this issue Aug 5, 2024 · 9 comments
Open
Tracked by #54

Serve precompressed *.gz file #53

Eason0729 opened this issue Aug 5, 2024 · 9 comments
Assignees
Labels
C-Frontend Relate to frontend P-Low Low priority

Comments

@Eason0729
Copy link
Contributor

Eason0729 commented Aug 5, 2024

When using leptos-build, run with --pre-compress will compress all static wasm/js/css...

For example:

tree /site/
/site/
├── favicon.ico
├── favicon.ico.br
├── favicon.ico.gz
└── pkg
    ├── mdoj.css
    ├── mdoj.css.br
    ├── mdoj.css.gz
    ├── mdoj.js
    ├── mdoj.js.br
    ├── mdoj.js.gz
    ├── mdoj.wasm
    ├── mdoj.wasm.br
    └── mdoj.wasm.gz

By just serving compressed content, we can save about 70% of bandwidth.

However, leptos-build won't help you serving them, you need to write them in actual code.

@KAIYOHUGO KAIYOHUGO self-assigned this Aug 5, 2024
@KAIYOHUGO
Copy link
Contributor

I will take this.

@KAIYOHUGO KAIYOHUGO mentioned this issue Aug 5, 2024
2 tasks
@KAIYOHUGO
Copy link
Contributor

@Eason0729
Copy link
Contributor Author

It's okay to use middleware to compress on fly(low level compression ratio for more speed).

But if possible, it better to use pre-compressed file provieded by leptos build(high level compression ratio).

I would consider this issue low priority.

@Eason0729
Copy link
Contributor Author

You can check Accept-Encoding: gzip, deflate, br, zstd, response with corresponding header (.set_content_encoding(ContentEncoding::Gzip) and binary content.

@KAIYOHUGO
Copy link
Contributor

It's okay to use middleware to compress on fly(low level compression ratio for more speed).

I mean this section (about pre compressed)
https://docs.rs/actix-web/4.8.0/actix_web/middleware/struct.Compress.html#pre-compressed-payload

@KAIYOHUGO
Copy link
Contributor

KAIYOHUGO commented Aug 9, 2024

Maybe we should utilize GitHub's issue tagging system

@Eason0729 Eason0729 added P-Low Low priority good first issue Good for newcomers labels Aug 10, 2024
@Eason0729
Copy link
Contributor Author

Maybe we should utilize GitHub's issue tagging system

For low priority or just categorize issue?

@Eason0729
Copy link
Contributor Author

I would work on a example accommodating our use case.

Such that it includes those logic:

  1. Determine which content encoding can be used.
  2. Determine whether such file (Ex: for http://example.com/pkg/mdoj.wasm and gzip, we should use /pkg/mdoj.wasm.gz) exist.
  3. Serve the file without reaching file directly.

@Eason0729
Copy link
Contributor Author

After some offline discussion, we conclude that we could have pre-compressed enabled with axum:

Reason for such decision:

  1. axum have bulit in support(doesn't need to write much of code)
  2. using axum in this project improve compile(tonic and axum has a lot of common dependency)

Also of note, there is a pull request attending to add pre-compressed static file support, but leave in review for about 1.5 years.

@KAIYOHUGO KAIYOHUGO added C-Frontend Relate to frontend and removed good first issue Good for newcomers labels Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Frontend Relate to frontend P-Low Low priority
Projects
None yet
Development

No branches or pull requests

2 participants