-
Notifications
You must be signed in to change notification settings - Fork 4
Fastly & Caching
As MMA displays sensitive information, only static assets are cached both in
- Fastly, and in
- application itself via the
Cache-Control
header inserver.ts
. Make sure to put sensitive route underdisableCache
middleware call.
As of this date, static assets are no longer served from our ECB servers, and rather stored and served from an S3 bucket called manage-frontend-static
. Rules have been set in Fastly to point to this new bucket. The reason for this change was due to a number of chunkload errors, i.e.: the client requesting a javascript file (e.g.: 277.1b33cd48146f612223fb.js
) and the server would return a 404 error. These 404 errors were happening with each new deployment. During deploy, webpack would generate new javascript files/bundles, each with a unique ID. These would then replace the old javascript bundles on the server, the client would then request the old javascript file/bundle which would result in the 404.
Force PASS (do not cache) by default on all routes, unless route is explicitly enabled to be cacheable:
To enable caching explicitly for a route newroute
:
- Modify VCL condition to
req.url !~ "^/(static|newroute)"
- Add the route above
disableCache
middleware inserver.ts
or override cache-control headers on case-by-case basis.
Relevant links
- Learnt the hard way to avoid any sensitive user responses from being cached - very important: #43, #138, #140 we learnt the hard way to set the
Cache-Control
header, which is set to"private, no-cache, no-store, must-revalidate, max-age=0"
ALL responses but overridden for the static assets (see #183). - Change Fastly to by default not cache unless route is explicitly added to allow-list #568 https://github.com/guardian/manage-frontend/pull/568
- Controlling caching
- x-cache headers
Like many of the frontend platforms at the Guardian we use Fastly CDN.
We don't have complicated VCL and so everything has been done via Fastly UI, that said version controlling the generated VCL alongside our code wouldn't be a bad idea (we of course have version control via the Fastly UI). Notable things are...
- Healthcheck configured (
/_healthcheck
must be 200, checked every 60 seconds) - Force TLS and enable HSTS
- Sets geolocation
set-cookie
headers for all PROD and CODE traffic (VCL snippet) - Force PASS (no caching) by default on all endpoints (except static currently)
- GZIP enabled on any cached resources (see #183) which should only be
/static/
content (primarily the client-side bundleuser.js
) - Logging into
gu-reader-revenue-logs
S3 bucket
We have a project in Fastly for CODE too, which can be used to test configurations before PROD. Not also that https://manage.code.dev-theguardian.com/ is accessible from anywhere, unlike say https://support.code.dev-theguardian.com/ which is only available from the office IP.
- Might be best to make changes to VCL indirectly via UI instead of directly writing VCL code.
- First try all changes via CODE service manage.code.dev-theguardian.com
- Go to
Configure
tab https://manage.fastly.com/configure -
Switch service
tomanage.code.dev-theguardian.com
-
Edit Configuration
andClone
- A
Draft
version should be created, for example - Add informative comment describing the change
- Make changes
- Double check
Diff versions
- Perhaps link the diff to a PR if possible
- After peer review,
Activate
. - Repeat for PROD.
Not what you're looking for? Be sure to use the navigation sidebar on the right. ➡️