Add cache-control header to HTTP responses based on mime #41
Loading…
Reference in New Issue
No description provided.
Delete Branch "cache-control"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Got this deployed on https://test.lemmy.ml/.
Here is an analyis, note the result for "Leverage browser caching" https://gtmetrix.com/compare/IvgJgdKn/av79Z7K6
Some notes:
?
doesnt work (again, weird types)@ -54,0 +67,4 @@
}
Ok(res)
}
})
This seems kinda messy, the only cached resources need to be the static files: https://actix.rs/docs/static-files/
There should be a way to add the cache-control header to them directly, as well as the etags / last-modified.
Unfortunately I couldnt find any other way. Only thing I found would apply the headers to all requests. etag/last-modified are already set by default.
I'm asking the actix-web ppl in their gitter channel right now. Also is there any reason we couldn't do this through our nginx template,
I think maybe it didn't work but I don't remember.
Nginx should work, but I think its cleaner to handle this directly in Lemmy, in case people use a different reverse proxy. Or in case we want to change it in the future.
I'm trying to clean this up by moving the lambda into a seperate function, but it always ends with the error
expected bound lifetime parameter, found concrete lifetime
, no idea how to fix that.I pushed that version in case you want to have a look at it.
Asked on the Rust forum about this: https://users.rust-lang.org/t/how-to-fix-expected-bound-lifetime-parameter-found-concrete-lifetime/43677
Okay got it working thanks to a comment on the Rust forum!
Now the only question is what's a good value for max-age.
1 year is probably fine, I'll test this out now locally too.