您的位置:首页 > Web前端 > CSS

CSS JS 添加版本号

2015-10-29 20:23 621 查看
PHP实现 CSS文件添加版本号;JS添加版本号。

<?php
/*
*CSS、JS设置版本号
*/
function autoVer($url){
$ver = date("Y-m-d H:i:s",filemtime($_SERVER['DOCUMENT_ROOT'].$url)); //filemtime()读取文件修改的最新时间,返回时间戳。
echo $url.'?v='.$ver;
}
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
<link href="favicon.ico" rel="Bookmark" type="image/x-icon" />
-->
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
<link href="<?php autoVer('/css/css.css'); ?>" rel="stylesheet" type="text/css" > //取得版本号
<script src="<?php autoVer('/js/js.js'); ?>"></script> //取得版本号
</link>
</head>
<body>
<h1>Hello,world!</h1>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息