admin管理员组文章数量:1406944
I'm trying to pass the preload check of Google PSI, so i've placed the local fonts i got, in the <head>
as suggested using preload, as:
<link rel="preload" as="font" href="myfont.woff" type="font/woff2" crossorigin>
<link rel="preload" as="font" href="myfont.woff" type="font/woff2" crossorigin>
<link rel="preload" as="font" href="myfont2.woff" type="font/woff2" crossorigin>
problem is, something is versioning it, so PSI still report it as not preloaded showing me the url of the font is something like myfont.woff?18238125
, how can avoid versioning it, or strip the query at the end via php?
I'm trying to pass the preload check of Google PSI, so i've placed the local fonts i got, in the <head>
as suggested using preload, as:
<link rel="preload" as="font" href="myfont.woff" type="font/woff2" crossorigin>
<link rel="preload" as="font" href="myfont.woff" type="font/woff2" crossorigin>
<link rel="preload" as="font" href="myfont2.woff" type="font/woff2" crossorigin>
problem is, something is versioning it, so PSI still report it as not preloaded showing me the url of the font is something like myfont.woff?18238125
, how can avoid versioning it, or strip the query at the end via php?
1 Answer
Reset to default 0If you load your fonts using standard stylesheet enqueueing then you can add this to your functions.php file:
function remove_querystrings( $src ) {
$parts = explode( '.woff?ver', $src );
return $parts[0];
}
add_filter( 'style_loader_src', 'remove_querystrings', 15, 1 );
I haven't tested this but I'm fairly certain it will only work if you're adding the fonts with wp_enqueue_style();
.
I use the above in production environments to remove the query string from all scripts and styles not just fonts, but that's only on finalized sites where the only updates are to content. (On that note, I've never tested it with .woff
in front of the ?ver
.)
本文标签: queryPrevent versioning for woff (font) files
版权声明:本文标题:query - Prevent versioning for .woff (font) files 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744712223a2621196.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论