dqu3974 2018-08-26 07:51
浏览 93
已采纳

GTmetrix它说的是来自一致URL的服务资源

I have an issue with my Word-press site, When i tested with GTmetrix it is saying Serve resources from a consistent URL. and it showing that i have used 2 css files one with normal correct extension .css and another one with some version extension as last which is .css?ver=4.9.8. The correct one is the first one style.css. i do not know from where the other one is coming. I have not used anywhere in my knowledge. I have tried de-activating some plugins like cache from admin panel as per Google recommendations. But it does not work. https://gtmetrix.com/reports/pentaworkspace.com/z0ra5DhP

Please anyone help me on this?

error

  • 写回答

1条回答 默认 最新

  • dtwr2012 2018-08-26 11:01
    关注

    This CSS file is certainly queued by your theme. The code should be around function.php or related file. Try a search for wp_enqueue_script, and look for your problematic script name passed as a parameter.

    The version parameter in the URL is here to be able to clear browser cache: if your file is updated, but URL doesn't change: the browser will keep using his cached version and won't have updates displayed. Updating this ver parameter will force a browser to download and cache the file again.

    You can use a snippet like this to remove those parameters (now that you know why they are here, and what situation it can generate):

    function remove_wp_assets_qvar( $src ) {
        $src = preg_replace_callback( '/ver=[^&]*/', __NAMESPACE__ . '\emoveVersionCallback', $src );
        if ( strpos( $src, 'ver=' ) ) {
            $src = remove_query_arg( 'ver', $src );
        }
    
        return $src;
    }
    
    add_filter( 'style_loader_src', __NAMESPACE__ . '\emove_wp_assets_qvar', 9999 );
    add_filter( 'script_loader_src', __NAMESPACE__ . '\emove_wp_assets_qvar', 9999 );
    

    Infos: nowadays, a lot of assets pipeline (webpack, gulp...) are generating "versioned" build files with a unique hash in the filename to prevent those browser caching "issues".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?