Join GitHub today
Set different cache times for different assets #334
This continues the work started in #311
Currently, all files served from https://interactive-examples.mdn.mozilla.net have a max age of 900 seconds (15 minutes). This includes both the embedded samples HTML and the static assets shared among samples.
Users will re-request any file after 15 minutes. If the file hasn't changed, CloudFront should send a
This is probably OK. However, tools like https://www.webpagetest.org will advise us that some assets, such as codemirror.js, should have longer cache times. 1 week is usually the recommended minimum, but web page test will accept down to 1 hour.
We can use very long cache times for files that never change. If the file does change, we can change the name, so that it is a different file. Some asset pipelines allow you to embed a hash of the file in the name to get this effect, and others embed a version in the asset name.
Different cache times for different assets will complicate publishing to S3 (we can't just use
Here's my proposal:
With this proposal:
If you anticipate often adding or removing assets in /css and /js, then you'll need to split them into /css and /js (1-minute cache) and /css-lib and /js-lib (1-week cache). Different folders will allow us to use sync to upload them.