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

Cache-busting issues with static assets #21

Open
robertknight opened this issue Nov 24, 2016 · 1 comment
Open

Cache-busting issues with static assets #21

robertknight opened this issue Nov 24, 2016 · 1 comment

Comments

@robertknight
Copy link
Member

robertknight commented Nov 24, 2016

Note: This issue was originally filed against the h project, before we extracted the h-assets package and started using it across different projects.

Current issues with static assets and cache busting

  • Static asset URLs use query strings as cache busters. These are used when generating the asset but ignored when serving it. Consequently, it is possible that client may request 'foo.js' version 'v1' via a request for '/assets/foo.js?v1' but actually get a newer version 'v2'. This is a problem for Sentry if it tries to process an exception report for Hypothesis release v.X after Hypothesis v.X+1 has been released.
  • Sourcemap URLs do not include cache-busting tokens, so Sentry may end up trying to process an exception for '/assets/foo.js?v2' by requesting '/assets/foo.js.map' and actually end up using a cached sourcemap (where the sourcemap has been cached either by Sentry itself, or CloudFlare) for an earlier release.
  • Static assets are served with a short cache expiration of 4 hours, despite the fact that assets are immutable (provided they are cache-busted). This is a small inefficiency that may lead clients to download resources they already have.
  • Not all resources are served with cache-busting tokens in the URL. eg. SVG images are currently served without. This may lead to users seeing old versions of assets. Fixed

Proposed changes

@robertknight robertknight changed the title Cache busting issues with static assets Cache-busting issues with static assets Nov 24, 2016
robertknight referenced this issue in hypothesis/h Nov 28, 2016
Replace hard-coded '/asset' URL paths in templates with cache-busted
URLs generated from the site's static asset manifest.

See #4117
robertknight referenced this issue in hypothesis/h Nov 28, 2016
Replace hard-coded '/asset' URL paths in templates with cache-busted
URLs generated from the site's static asset manifest.

 * Add `asset_url` helper for retrieving the cache-busted URL for an
   asset with a given path and use it in templates.

 * Fix missing entries in asset manifest by including subdirectories
   (eg. 'images/icons/*.svg') and all extensions (eg. sourcemaps)

See #4117
robertknight referenced this issue in hypothesis/h Nov 28, 2016
Replace hard-coded '/asset' URL paths in templates with cache-busted
URLs generated from the site's static asset manifest.

 * Add `asset_url` helper for retrieving the cache-busted URL for an
   asset with a given path and use it in templates.

 * Fix missing entries in asset manifest by including subdirectories
   (eg. 'images/icons/*.svg') and all extensions (eg. sourcemaps)

See #4117
nickstenning referenced this issue in hypothesis/h Nov 29, 2016
Replace hard-coded '/asset' URL paths in templates with cache-busted
URLs generated from the site's static asset manifest.

 * Add `asset_url` helper for retrieving the cache-busted URL for an
   asset with a given path and use it in templates.

 * Fix missing entries in asset manifest by including subdirectories
   (eg. 'images/icons/*.svg') and all extensions (eg. sourcemaps)

See #4117
@robertknight
Copy link
Member Author

Status update for May 2023: The code for serving static assets was extracted into the h-assets package. That still uses query strings as cache busters, but it does validate them and return a 404 if the cache buster query string is invalid.

This resolves the first problem where Sentry could end up receiving a bug report for version X and end up fetching the static asset for a later release Y.

However this problem is still open:

Sourcemap URLs do not include cache-busting tokens

The challenge here is that the sourcemap URL is part of the JS / CSS bundle generated by Rollup or PostCSS respectively.

@robertknight robertknight transferred this issue from hypothesis/h May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants