PluginProbe
EasyFonts – Host Google Fonts Locally, Fast & Auto-Optimize, GDPR Compliant / 2.0.4
EasyFonts – Host Google Fonts Locally, Fast & Auto-Optimize, GDPR Compliant v2.0.4
2.0.4 2.0.3 2.0.2 2.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2 1.3 2.0.0
← All changes | src/Fonts/Storage.php +23 -0 2.0.3 → 2.0.4 View file →
@@ -80,8 +80,31 @@
80 80 return self::cdn_rewrite( $url );
81 81 }
82 82
83 83 /**
84 + * Public URL of a hosted FONT, versioned by the file itself.
85 + *
86 + * (2.0.4) Font URLs used to carry the site-wide cache-buster, which every
87 + * settings save bumps. The consolidated stylesheet is written once and
88 + * reused, so its @font-face URLs kept the old buster while preloads took
89 + * the new one: two URLs for one file — the preload went unused ("preloaded
90 + * but not used") and the font downloaded twice. A file's own modification
91 + * time changes only when the file itself is (re)written, so every place
92 + * that links a font — stylesheet, preload, localised theme CSS — computes
93 + * the same URL, and a settings save no longer makes every returning visitor
94 + * download every font again. Fonts are served immutable for a year, so the
95 + * version is still needed for when a file really is re-downloaded.
96 + *
97 + * @param string $filename Cache-relative font filename.
98 + * @return string
99 + */
100 + public function font_url( string $filename ): string {
101 + $mtime = @filemtime( $this->path( $filename ) ); // phpcs:ignore WordPress.PHP.NoSilencedErrors
102 +
103 + return add_query_arg( 'ver', $mtime ? (int) $mtime : \EasyFonts\Settings::buster(), $this->url( $filename ) );
104 + }
105 +
106 + /**
84 107 * Rewrite a same-origin asset URL onto the configured CDN origin.
85 108 *
86 109 * The CDN value is treated as an origin (scheme + host[/optional base]);
87 110 * the asset path is preserved. Returns the URL unchanged when no CDN is set,