Set an expiry date or max age HTTP header for font resources

RESOLVED FIXED

Status

Mozilla Developer Network
Performance
--
minor
RESOLVED FIXED
3 years ago
3 years ago

People

(Reporter: groovecoder, Unassigned)

Tracking

({in-triage})

Details

Attachments

(1 attachment)

Severity: normal → minor
Component: Performance → Code Cleanup
Keywords: in-triage
Component: Code Cleanup → Performance
So first of all, this is an issue that not only happens to our styles (base/fonts/opensans.styl) but also happens to files in the Tabzilla CSS: https://mozorg.cdn.mozilla.net/media/css/tabzilla-min.css

I'm not sure why we need to use the mozorg.cdn.mozilla.net to be honest, I guess that's to make sure the files are properly cached from one central Mozilla source instead of ten of all the various Mozilla websites. And I guess the low expiry could be there so the file serving works without having to use a cache busting hash in the URL.

On the other hand this could be an issue with the httpd or load balancer setup of not setting long expiry values for font files correctly. I'm not sure.

Options:

1. Ask webops to check if the mozorg.cdn.mozilla.net setup is correct and fix it if possible.

2. Host font files on our own CDN (developer.cdn.mozilla.net) and stop depending on mozorg.cdn.mozilla.net. That would probably also mean to stop serving Tabzilla as well.

Leaving it to Stephanie to make a decision :)
:pmac Do you know what's wrong with the mozorg CDN?
:craigcook Or maybe you can shed some light on this?
Flags: needinfo?(pmac)
Flags: needinfo?(craigcook.bugz)
The short answer is that this is the default cache expiry for static files on bedrock. We could make it longer. We use hashed file names in bedrock itself so that we can set effectively infinite cache timeouts for most files, but sites outside of bedrock that don't have access to the manifest mapping of original file names to hashed file names can't do that.

The best solution for you is to host the files yourself. Tabzilla is about to be replaced by a much more simple and static thing (https://bugzilla.mozilla.org/show_bug.cgi?id=1151579) so you'll need to host your own fonts at that point anyway since new Tabzilla won't require them.

Another option is to just use our hashed version of the tabzilla CSS, which is very unlikely to change now that we're working on the new thing:

https://mozorg.cdn.mozilla.net/media/css/tabzilla-min.c4e071344612.css

But that does carry some risk. It should stay there as we don't delete these generated files, and the CDN should cache them for 10 years, but I can understand if you're reluctant to use that. It could be a decent interim solution if you need a quick one though.

Hope this helps. We're happy to make whatever changes you need though. If you have a recommendation for a better default cache timeout I'm quite happy to change that as well.
Flags: needinfo?(pmac)
Flags: needinfo?(craigcook.bugz)
(Reporter)

Comment 5

3 years ago
https://developers.google.com/speed/docs/insights/LeverageBrowserCaching:

"We recommend a minimum cache time of one week and preferably up to one year for static assets, or assets that change infrequently."

Since I assume these font assets don't change much at all, could we set the cache timeout to 1 week?
Flags: needinfo?(pmac)
:groovecoder Could we just start hosting those files on our own once pipeline is merged?
(Reporter)

Comment 7

3 years ago
Yeah, I like that best as a long-term, across-the-site fix for proper browser caching. I only filed the bug for these assets because they are the only ones reported by Google Analytics with such a short expiration.

:pmac - how long would it take to make the default cache timeout change on your side? Can you do that while we work on django-pipeline to host the files on our own?
Yup. I'll set the font files to a month by default. Cool? The simple and static tabzilla release is imminent by the way:

https://github.com/mozilla/tabzilla

There will be an email to the public webdev list when it's fully ready.
Flags: needinfo?(pmac)
Created attachment 8634331 [details] [review]
Link to Github pull-request: https://github.com/mozilla/bedrock/pull/3128

This PR sets cache-control header for all files under the /media/fonts/ URL to 30 days. It also increases the default expiry for all non-immutable files to 6 hours instead of 1 minute.

Comment 10

3 years ago
Commits pushed to master at https://github.com/mozilla/bedrock

https://github.com/mozilla/bedrock/commit/17208e0327bef65a787b22c1e9b44385c338ceda
Bug 1182126: Increase fonts cache header to one month.

Also increase default cache header expiry to 6 hours from 1 minute.
The majority of files used on bedrock are immutable (include the
file content hash) and will be unaffected by this change.

https://github.com/mozilla/bedrock/commit/d6c6212fbd424733a46898bd4200f4734c010b63
Merge pull request #3128 from pmclanahan/increase-fonts-cache-expire-1182126

Bug 1182126: Increase fonts cache header to one month.
(Reporter)

Comment 11

3 years ago
Thanks :pmac! As of this change, GA speed suggestions no longer mentions these assets. Do you know when this was deployed, so I can check before/after page speed numbers in GA?
Status: NEW → RESOLVED
Last Resolved: 3 years ago
Flags: needinfo?(pmac)
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.