query - Prevent versioning for .woff (font) files

I'm trying to pass the preload check of Google PSI, so i've placed the local fonts i got, in the <head>

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?

Share Improve this question edited Feb 27, 2020 at 7:28 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Feb 27, 2020 at 0:05 RobertRobert 1112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

If 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.)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744712224a4589410.html

相关推荐

  • query - Prevent versioning for .woff (font) files

    I'm trying to pass the preload check of Google PSI, so i've placed the local fonts i got, in the <head>

    18小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信