salvo-compression
Compress HTTP responses using gzip, brotli, zstd, or deflate. Use for reducing bandwidth and improving load times.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Compress HTTP responses using gzip, brotli, zstd, or deflate. Use for reducing bandwidth and improving load times.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Guide for using RBatis v4 Rust ORM framework. Use when implementing database CRUD operations, writing dynamic SQL with py_sql or html_sql macros, configuring database connections, managing transactions, implementing interceptors, syncing table structures, or integrating RBatis into Genies microservices. Also use when the user asks about RBatis usage patterns, query building, or database operations in Rust.
Genies 前后端接口规范。Use when designing API contracts, defining field naming conventions, date/time formats, response models, pagination, error handling, or ID strategies between Genies backend and frontend (Web/Android/OHOS).
Guide for using flyway-rs database migration framework with RBatis. Use when implementing database schema migrations, managing SQL changelog files, configuring migration runners, handling multi-database migrations, or integrating database versioning into Genies microservices.
Guide for developing Rust microservices using Genies framework following Java DDD layering principles. Use when creating new microservices, designing aggregate roots, implementing domain events, organizing service layers, setting up Flyway migrations, or structuring a DDD-based Genies project.
Genies framework unified skill hub. Use when you need to find the right skill for any Genies framework task, including authentication, authorization, caching, configuration, database, DDD microservices, Dapr messaging, macros, K8s deployment, testing, API conventions, gateway proxy, or Salvo web framework features. Also use when the user asks about Genies framework capabilities, asks which skill to use, or wants a quick overview of available Genies skills.
Guide for using the Genies Rust microservice framework with DDD and Dapr. Use when developing with Genies, creating aggregates, domain events, Dapr subscriptions, Casbin field-level permissions, configuration management, or when the user asks about Genies framework usage patterns.
| name | salvo-compression |
| description | Compress HTTP responses using gzip, brotli, zstd, or deflate. Use for reducing bandwidth and improving load times. |
| version | 0.89.3 |
| tags | ["performance","compression","gzip","brotli"] |
This skill helps configure response compression in Salvo applications.
[dependencies]
salvo = { version = "0.89.3", features = ["compression"] }
use salvo::prelude::*;
use salvo::compression::Compression;
#[handler]
async fn large_response() -> String {
"This response will be compressed if the client supports it. ".repeat(100)
}
#[tokio::main]
async fn main() {
let router = Router::new()
.hoop(Compression::new())
.get(large_response);
let acceptor = TcpListener::new("0.0.0.0:8080").bind().await;
Server::new(acceptor).serve(router).await;
}
| Algorithm | Description |
|---|---|
| Gzip | Most widely supported, good balance |
| Brotli (br) | Best compression ratio, higher CPU |
| Zstd | Fast with good compression |
| Deflate | Legacy, rarely used alone |
use salvo::compression::{Compression, CompressionLevel};
// Only gzip
let gzip_only = Compression::new()
.enable_gzip(CompressionLevel::Default);
// Only brotli
let brotli_only = Compression::new()
.enable_brotli(CompressionLevel::Best);
// Multiple algorithms
let multi = Compression::new()
.enable_gzip(CompressionLevel::Default)
.enable_brotli(CompressionLevel::Default)
.enable_zstd(CompressionLevel::Default);
use salvo::compression::CompressionLevel;
CompressionLevel::Fastest // Fastest speed, lower compression
CompressionLevel::Default // Balanced speed and compression
CompressionLevel::Best // Best compression, slower
CompressionLevel::Precise(6) // Exact level (algorithm-specific)
let compression = Compression::new()
.min_length(1024); // Only compress responses > 1KB
let compression = Compression::new()
.content_types(vec![
"text/html",
"text/css",
"text/javascript",
"application/json",
"application/xml",
"image/svg+xml",
]);
use salvo::compression::{Compression, CompressionLevel};
use salvo::prelude::*;
#[tokio::main]
async fn main() {
let static_compression = Compression::new()
.enable_brotli(CompressionLevel::Best)
.enable_gzip(CompressionLevel::Best);
let api_compression = Compression::new()
.enable_gzip(CompressionLevel::Fastest)
.min_length(256);
let router = Router::new()
.push(
Router::with_path("static")
.hoop(static_compression)
.get(StaticDir::new("./public"))
)
.push(
Router::with_path("api")
.hoop(api_compression)
.get(api_handler)
);
let acceptor = TcpListener::new("0.0.0.0:8080").bind().await;
Server::new(acceptor).serve(router).await;
}
use salvo::compression::{Compression, CompressionLevel};
use salvo::prelude::*;
use serde::Serialize;
#[derive(Serialize)]
struct LargeResponse {
items: Vec<String>,
}
#[handler]
async fn large_json() -> Json<LargeResponse> {
Json(LargeResponse {
items: (0..1000).map(|i| format!("Item {}", i)).collect(),
})
}
#[tokio::main]
async fn main() {
let compression = Compression::new()
.enable_gzip(CompressionLevel::Default)
.enable_brotli(CompressionLevel::Default)
.min_length(512)
.content_types(vec![
"text/html",
"text/css",
"application/json",
"application/javascript",
]);
let router = Router::new()
.hoop(compression)
.push(Router::with_path("api/data").get(large_json));
let acceptor = TcpListener::new("0.0.0.0:8080").bind().await;
Server::new(acceptor).serve(router).await;
}