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

Support client caching #97

Open
kpcyrd opened this issue May 22, 2017 · 3 comments
Open

Support client caching #97

kpcyrd opened this issue May 22, 2017 · 3 comments

Comments

@kpcyrd
Copy link

kpcyrd commented May 22, 2017

I'm trying to serve assets using this crate, but I've noticed the server does not send an Etag. This would cause the client to request the asset every time it's referenced (so, on every page load).

The express framework is sending an etag on static mounts, the client would memorize this and include it in future requests, if the server notices the file hasn't changed, it's sending back an 304.

This is critical for page speed and bandwidth. :)

@vmchale
Copy link

vmchale commented May 22, 2017

If you add

staticfile = {version = "0.4", features=["cache"]}

to your Cargo.toml, it will enable caching.

@vmchale
Copy link

vmchale commented May 22, 2017

Here is an example:

use staticfile::{Static, Cache};
use std::time::Duration;

...

    let one_week = Duration::new(7*24*3600,0);
    let mut css_stat = Static::new(Path::new("static/css"));
    Cache::new(one_week).modify(&mut css_stat);
    router.mount("/css/", css_stat);

@Hoverbear
Copy link

Perhaps we should add some documentation of this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants