在functions.php 增加V函数 用于更新静态文件版本,强制更新缓存

分享 未结
0 2721
番茄
番茄 VIP 1 2018-04-10
悬赏:0

在functions.php 增加函数

/**
 * 获取文件最后修改时间
 * 用于更新静态文件版本号
*/
function V($file_path){
    /*$file_path = ltrim($file_path,'<?php echo __RES__; ?>');去掉__RES__*/ 
    if( file_exists(RES.$file_path) ) {
        $newVer = filemtime( RES.$file_path );
    }
    $ver = $newVer ? : 1;
    return __RES__.$file_path .'?v=' . $ver;
}


在模板文件中使用

<script type="text/javascript" src="<{:V('/js/list.js')}>"></script>


回帖

温馨通道

最近回贴

最近热议
没有相关数据