Skip to content

[Feature Request] Optional Asset Compression #91

Open
@quinnjr

Description

@quinnjr

Feature Request - Optional Asset Compression

This feature request asks for the implementation of optional asset compression by trunk.

trunk would follow a similar pattern to webpack-compression-plugin by allowing users to configure --build asset compression for all files generated by trunk.

NOTE

In relation to #81, I've checked and confirmed that actix-web and warp support serving compressed assets.

Example

Cargo.toml changes

...

[features]
compression = []
gzip-compression = ["compression", "flate2"]
...

[dependencies]
...
flate2 = { version = "1.0.18", default-features = false, features = ["tokio", "zlib"], optional = true }

Configuration in Trunk.toml

...
[[compression]]
# Specifies the compression algorithm.
algorithm = "gzip" 
# Options to pass to the compression algorithm. Optional.
# Ex: Passing the `level` option to gzip
options = { level = 6 }
# A RegExp test to pass to include assets that pass the RegExp test. Optional.
test: "/\.(js|css|png|wasm)(\?.*)?$/i"
# Allow for inclusion of certain assets via glob. Optional.
include = []
# Allow for exclusion of certain assets via glob. Optional.
exclude = ["favicon.ico", "*.gz"]
# Size of asset (in bytes) that should be compressed. Less than the threshold will not be compressed. Optional.
threshold = 8192
ratio = 0.8 # Minimum compressed asset size ratio for output. Optional.

Algorithm Targets

  • zlib (Deflate, gzip) (flate2)
  • brotli
  • zopfli (Rust support??)
  • zstd (zstd, gzip)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionThis item needs some discussionenhancementNew feature or requestneeds designThis item needs design work

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions