Static Files on the CDN
While SMARTER_PLATFORM_STATIC_FILES_ON_CDN is on, the platform’s static files, the web console’s scripts
among them, are stored in the environment’s S3 bucket, under static/, and pages load them from
its CDN, cdn.<platform>. initialize_platform uploads them on each deployment, then records the
console’s build, and the console’s page switches to the CDN only once its build is recorded. Until
then, and whenever the setting is off, the server serves them itself. See
ADR-035.
The static files’ storage on the environment’s S3 bucket, behind its CDN, while SMARTER_PLATFORM_STATIC_FILES_ON_CDN is on.
collectstatic, which initialize_platform runs on each deployment, uploads the files under static/, and
pages load them from the CDN, e.g. https://cdn.platform.example.com/static/. A React app’s build output under
assets/ has content-hashed names, so a browser may keep it for a year; every other file, e.g. a Keen theme
asset that templates version with a query string, may be kept for an hour. collectstatic adds and replaces
files, and deletes none, so a page that a browser opened before a deployment keeps loading its scripts.
initialize_platform runs after a deployment’s new pods start, so a new page must not point at the CDN before its
files are there: mark_uploaded() records a file once its upload is done, and is_uploaded() says whether
it is, from that record, or, after the cache was cleared, from the bucket itself.
See ADR-035 and smarter.apps.dashboard.views.console_app.
- smarter.lib.django.static_storage.DEFAULT_CACHE_CONTROL = 'public, max-age=3600'
Cache-Control of any other static file.
- smarter.lib.django.static_storage.HASHED_CACHE_CONTROL = 'public, max-age=31536000, immutable'
Cache-Control of a file whose name changes with its content.
- smarter.lib.django.static_storage.STATIC_LOCATION = 'static'
The folder of the bucket that holds the static files.
- class smarter.lib.django.static_storage.SmarterStaticFilesStorage(*args, **kwargs)[source]
Bases:
S3StorageThe static files on the environment’s S3 bucket, under
static/, each with its own Cache-Control.
- smarter.lib.django.static_storage.cache_control(name)[source]
The Cache-Control header of a static file.
- smarter.lib.django.static_storage.is_uploaded(name)[source]
Whether a static file is on the CDN’s bucket.
It is if
mark_uploaded()recorded it, or, without that record, e.g. after the cache was cleared, if the bucket has it, which is then recorded.