Skip to content

Add asset caching #16

@448-OG

Description

@448-OG
  • Add asset caching using HTTP headers
  • Check validity of CDN caching tools for both push and pull, checking whether there is a unified protocol for this, if not add a way to point the CDNs to assets for the url in settings

Note that axum server decides how the caching is handled, if caching is CDN based or not, for example:

use axum::{
    response::{Html, IntoResponse},
    http::header,
};

async fn ssr_handler() -> impl IntoResponse {
    let html = render_ssr_html();

    (
        [
            (header::CACHE_CONTROL, "no-store"),
            (header::PRAGMA, "no-cache"),
        ],
        Html(html),
    )
}

use tower_http::services::ServeDir;

let assets = ServeDir::new("assets")
    .precompressed_gzip()
    .with_cache_control("public, max-age=31536000, immutable");

Router::new().nest_service("/assets", assets);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions