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

All: add jq_url_append_version() #470

Merged
merged 2 commits into from
Oct 13, 2024
Merged

All: add jq_url_append_version() #470

merged 2 commits into from
Oct 13, 2024

Conversation

Krinkle
Copy link
Member

@Krinkle Krinkle commented Oct 12, 2024

  • Switch from central list to per-url hash. This removes the need to know about and remember updating a central list. I noticed one file missing already, namely the typesense-minibar.js file.

    This slightly improves cache use by not invalidating them all together.

  • The filemtime timestamp values are so short that an MD5 hash of three filemtime() values is actually longer than just the three numbers concatenated. This means we lack the benefit a hash usually provides, which is that you get exposure to high entropy input in a format shorter than that same input.

  • Switch from mtime (or mtime-hash) to content-hash. This has a few benefits:

    • Note that Git does not track modified times. Instead, mtime is whenever a git clone, checkout or pull last created or modified the file locally on that server. For example, if you git checkout OLD and then back to git checkout main, the files get a newer mtime. This is what happens by default at the OS level. Git isn't setting these mtime values.

      This means the URL ends up alternating depending on which server (e.g. wp-04 and wp-05) last generated the page. It also means different pages on the site may have a different URLs for the same asset, thus making ineffective use of caching. If the site was statically generated in CI, it would bump the cache after every commit instead of only when that file has changed, because in CI the "git clone" woulld create/modify all files at that time.

    • It is the same between local, staging, and production, which might ease debugging in some cases.

    • It allows continuing and re-using old browser (and CDN) caches if a commit is rolled back for some reason, since it would literally be the same content and thus URL again.

Follows-up 2015fcb.

Ref #469 Ref #468

@Krinkle Krinkle requested a review from timmywil October 12, 2024 20:14
* Switch from central list to per-url hash.
  This removes the need to know about and remember updating a
  central list. I noticed one file missing already, namely the
  typesense-minibar.js file.

  This slightly improves cache use by not invalidating them
  all together.

* The filemtime timestamp values are so short that an MD5 hash of three
  filemtime() values is actually longer than just the three numbers
  concatenated. This means we lack the benefit a hash usually provides,
  which is that you get exposure to high entropy input in a format
  shorter than that same input.

* Switch from mtime (or mtime-hash) to content-hash.
  This has a few benefits:
  - Note that Git does not track modified times.
    Instead, mtime is whenever a `git clone`, `checkout` or `pull`
    last created or modified the file locally on that server. For
    example, if you `git checkout OLD` and then back to
    `git checkout main`, the files get a newer mtime. This is what
    happens by default at the OS level. Git isn't setting these
    mtime values.

    This means the URL ends up alternating depending on which server
    (e.g. wp-04 and wp-05) last generated the page. It also means
    different pages on the site may have a different URLs for the
    same asset, thus making ineffective use of caching. If the site
    was statically generated in CI, it would bump the cache after every
    commit instead of only when that file has changed, because in CI
    the "git clone" woulld create/modify all files at that time.

  - It is the same between local, staging, and production, which
    might ease debugging in some cases.

  - It allows continuing and re-using old browser (and CDN) caches
    if a commit is rolled back for some reason, since it would
    literally be the same content and thus URL again.

Follows-up 2015fcb.

Ref #469
Ref #468
@Krinkle Krinkle force-pushed the append-content-hash branch from 06069fe to 03f6960 Compare October 12, 2024 20:32
Copy link
Member

@timmywil timmywil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is better

@Krinkle Krinkle merged commit 7273897 into main Oct 13, 2024
9 checks passed
@Krinkle Krinkle deleted the append-content-hash branch October 13, 2024 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants