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

Client caching #1545

Merged
merged 3 commits into from Mar 28, 2021
Merged

Client caching #1545

merged 3 commits into from Mar 28, 2021

Conversation

RealOrangeOne
Copy link
Contributor

Cache icons on the client too, to reduce requests when loading the homepage.

Caching without immutable will still issue requests, and because Rocket doesn't support conditional GETs, it's basically like not caching at all.

This also caches vault static files, which are cachebusted anyway so updates will still work fine. I've not changed the / route for this reason.

Bitwarden upstream doesn't do these, but they also use cloudflare for a CDN which makes this far less of an issue. For home users who don't use a global CDN, this should make quite a difference!

This should make the vault pages load much faster, and massively reduce the number of requests.
The URLs are cachebusted, so updates will still be applied cleanly and immediately
src/api/icons.rs Outdated
@@ -51,7 +51,10 @@ fn icon(domain: String) -> Option<Cached<Content<Vec<u8>>>> {
return None;
}

get_icon(&domain).map(|icon| Cached::long(Content(ContentType::new("image", "x-icon"), icon)))
get_icon(&domain).map(|(icon, cached)| {
let cache_ttl = if cached {CONFIG.icon_cache_ttl()} else {CONFIG.icon_cache_negttl()};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this use of cached makes sense, if you return an icon, you should always use the icon_cache_ttl.

The case when icon_cache_negttl would be used is when the icon couldn't be found, so get_icon returns None, and Rocket returns a 404, no idea if the browsers respect the cache headers in the case of a 404 though.

Copy link
Collaborator

@BlackDex BlackDex Mar 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 404's arn't cached.
Also, the time should be calculated depending on the time of the icon file and the ttl set for this to work correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah looks like I misread the implementation.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BlackDex I don't think it would be worth it to calculate the ttl based on the file date, at worst as it is now, a browser could cache a file for the full ttl while it's close to expired, which would mean it's outdated by an extra month by default if the clients respect the full ttl, but it would complicate the code for not much benefit, and I don't expect the favicons to change that much anyway.

@dani-garcia dani-garcia merged commit 01d8056 into dani-garcia:master Mar 28, 2021
@RealOrangeOne RealOrangeOne deleted the icon-client-cache branch March 28, 2021 15:40
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

Successfully merging this pull request may close these issues.

None yet

3 participants