提升网站速度js 脚本文件进行压缩

在需要压缩的 js 文件的开头加上:

< ?php
// check to see if the user has enabled gzip compression in the WordPress admin panel
if ( ob_get_length() === FALSE and !ini_get(’zlib.output_compression’) and ini_get(’output_handler’) != ‘ob_gzhandler’ and ini_get(’output_handler’) != ‘mb_output_handler’ ) {
ob_start(’ob_gzhandler’);
}
// The headers below tell the browser to cache the file and also tell the browser it is JavaScript.
header(”Cache-Control: public”);
header(”Pragma: cache”);
$offset = 60*60*24*60;
$ExpStr = “Expires: “.gmdate(”D, d M Y H:i:s”,time() + $offset).” GMT”;
$LmStr = “Last-Modified: “.gmdate(”D, d M Y H:i:s”,filemtime(__FILE__)).” GMT”;
header($ExpStr);
header($LmStr);
header(’Content-Type: text/javascript; charset: UTF-8′);
?>
声明: 本文采用 BY-NC-SA 协议进行授权 | helloyi
转载请注明转自《提升网站速度js 脚本文件进行压缩

给我留言

留言没头像?这里教你设置头像!