| @@ -915,10 +915,9 @@ | ||
| 915 | 915 | * --------------------------------------------------------------------- */ |
| 916 | 916 | |
| 917 | 917 | /** |
| 918 | 918 | * Register every variant and write one consolidated stylesheet. The file is |
| 919 | - * keyed by the variant set + display + subsets, so pages sharing fonts share | |
| 920 | - * the file. | |
| 919 | + * named by its content, so pages sharing fonts share the file. | |
| 921 | 920 | * |
| 922 | 921 | * Registration runs for EVERY variant on every request (idempotent upsert), |
| 923 | 922 | * even when the consolidated file already exists — so the hosted-fonts list |
| 924 | 923 | * can't drift out of sync with what's actually served. Font binaries are |
| @@ -973,23 +972,15 @@ | ||
| 973 | 972 | |
| 974 | 973 | $emit[ $key ] = true; |
| 975 | 974 | } |
| 976 | 975 | |
| 977 | - // Cache key = the EMITTED set (+ display + subsets). Two pages that emit | |
| 978 | - // the same faces share one file; a page whose enabled set differs gets | |
| 979 | - // its own. If the keyed file already exists we never rewrite it — | |
| 980 | - // identical sets are deduped on disk, so we don't burn IO/CPU | |
| 981 | - // regenerating the same stylesheet. | |
| 976 | + // The emitted set (+ display + subsets), recorded on each variant row as | |
| 977 | + // its css_file. The stylesheet itself is named by its CONTENT (below). | |
| 982 | 978 | $emit_keys = array_keys( $emit ); |
| 983 | 979 | sort( $emit_keys ); |
| 984 | 980 | $hash = substr( hash( 'sha256', implode( '|', $emit_keys ) . '|' . $display . '|' . $subsets ), 0, 20 ); |
| 981 | + $file = 'css/' . $hash . '.css'; | |
| 985 | 982 | |
| 986 | - // Consolidated stylesheet lives in a readable `css/` folder. Font | |
| 987 | - // binaries live under `fonts/{family}/…` so identical variants are | |
| 988 | - // shared across stylesheets. | |
| 989 | - $file = 'css/' . $hash . '.css'; | |
| 990 | - $file_exists = $this->storage->exists( $file ); | |
| 991 | - | |
| 992 | 983 | // M-3: one batched read of the rows we already have for every detected |
| 993 | 984 | // variant, so registration costs a single SELECT instead of one per |
| 994 | 985 | // variant. We then only write rows that are new or whose font file |
| 995 | 986 | // changed — on a warm-cache render that means zero writes. |
| @@ -1054,9 +1045,9 @@ | ||
| 1054 | 1045 | if ( ! $is_emitted || null === $font_file ) { |
| 1055 | 1046 | continue; |
| 1056 | 1047 | } |
| 1057 | 1048 | |
| 1058 | - $local_url = add_query_arg( 'ver', Settings::buster(), $this->storage->url( $font_file ) ); | |
| 1049 | + $local_url = $this->storage->font_url( $font_file ); | |
| 1059 | 1050 | $css .= $this->build_face_rule( $v, $local_url, $display ); |
| 1060 | 1051 | |
| 1061 | 1052 | self::$touched[] = array( |
| 1062 | 1053 | 'family' => $v['family'], |
| @@ -1070,19 +1061,25 @@ | ||
| 1070 | 1061 | if ( 0 === $hosted ) { |
| 1071 | 1062 | return null; |
| 1072 | 1063 | } |
| 1073 | 1064 | |
| 1074 | - // Deterministic content for a given emit set: only write when the keyed | |
| 1075 | - // file doesn't already exist. | |
| 1076 | - if ( ! $file_exists ) { | |
| 1077 | - if ( ! $this->storage->write( $file, $css ) ) { | |
| 1065 | + // (2.0.4) Named by CONTENT. Keyed by the emitted set alone, a file written | |
| 1066 | + // once outlived any later change to what it should contain (a font | |
| 1067 | + // re-downloaded after Purge, a CDN switch) and kept serving stale URLs, | |
| 1068 | + // as did the inlined copy cached under its name. Identical content still | |
| 1069 | + // shares one file and is never rewritten; older files are left for | |
| 1070 | + // page-cached HTML that may still link them (Purge removes them). | |
| 1071 | + $sheet = 'css/' . substr( hash( 'sha256', $css ), 0, 20 ) . '.css'; | |
| 1072 | + | |
| 1073 | + if ( ! $this->storage->exists( $sheet ) ) { | |
| 1074 | + if ( ! $this->storage->write( $sheet, $css ) ) { | |
| 1078 | 1075 | return null; |
| 1079 | 1076 | } |
| 1080 | 1077 | } |
| 1081 | 1078 | |
| 1082 | - self::$stylesheet_file = $file; | |
| 1079 | + self::$stylesheet_file = $sheet; | |
| 1083 | 1080 | |
| 1084 | - return add_query_arg( 'ver', Settings::buster(), $this->storage->url( $file ) ); | |
| 1081 | + return add_query_arg( 'ver', Settings::buster(), $this->storage->url( $sheet ) ); | |
| 1085 | 1082 | } |
| 1086 | 1083 | |
| 1087 | 1084 | /** |
| 1088 | 1085 | * Find an already-downloaded font file for a basename (any known extension). |
| @@ -1350,9 +1347,9 @@ | ||
| 1350 | 1347 | $font_file = $dl['file']; |
| 1351 | 1348 | $size = $dl['size']; |
| 1352 | 1349 | } |
| 1353 | 1350 | |
| 1354 | - $local_url = add_query_arg( 'ver', Settings::buster(), $this->storage->url( $font_file ) ); | |
| 1351 | + $local_url = $this->storage->font_url( $font_file ); | |
| 1355 | 1352 | |
| 1356 | 1353 | $this->register_variant( $variant, $font_file, $size ); |
| 1357 | 1354 | |
| 1358 | 1355 | $css = $this->str_replace_once( $block['full'], rtrim( $this->build_face_rule( $variant, $local_url, $display ) ), $css ); |