zoukankan      html  css  js  c++  java
  • 项目在线压缩js

    <?php
    /*$src = 'js/myjs.js';
    $out = 'js/myjs.min.js';
    require 'class.JavaScriptPacker.php';

    $script = file_get_contents($src);

    $t1 = microtime(true);

    $packer = new JavaScriptPacker($script, 'Normal', true, false);
    $packed = $packer->pack();

    $t2 = microtime(true);
    $time = sprintf('%.4f', ($t2 - $t1) );
    //echo 'script ', $src, ' packed in ' , $out, ', in ', $time, ' s.', "\n";
    file_put_contents($out, $packed);
    */
    require 'class.JavaScriptPacker.php';
    /**
    * 在线压缩js函数
    * @param string $src 压缩文件路径,项目下的相对路径
    * @param string $packerPath 压缩后的新文件名,项目下的相对路径,可以为空
    * @return string $packerPath
    * autor:yuzhonghe113@126.com
    */

    function jsPacker($src,$packerPath=""){
    //$path=dirname(__FILE__);
    if(!file_exists($src)) exit("File Is Not Exist");
    $fileName=basename($src,'.js');//文件名
    $filePath=dirname($src);//文件路径
    if(empty($packerPath)){
    $packerPath=$filePath."/".$fileName.".min.js";//压缩后的新文件名
    }
    //print_R(filemtime($packerPath)."|".filemtime($src));exit;
    if(file_exists($packerPath)&& filemtime($packerPath)>filemtime($src)){
    return $packerPath;
    }else{
    $script = file_get_contents($src);
    //$t1 = microtime(true);
    $packer = new JavaScriptPacker($script, 'Normal', true, false);
    $packed = $packer->pack();
    //$t2 = microtime(true);
    //$time = sprintf('%.4f', ($t2 - $t1) );
    //echo 'script ', $src, ' packed in ' , $out, ', in ', $time, ' s.', "\n";
    file_put_contents($packerPath, $packed);
    }
    return $packerPath;
    }
    ?>

    文件下载

  • 相关阅读:
    原型和原型链
    面向对象
    git在idea中的使用,如何构远程git方仓库
    java maven 安装
    Kafka消费者APi
    Kafka生产者APi
    kafka基本概念
    redis常用命令
    redis.conf配置文件参数说明
    Redis.RedisNativeClient的方法get_Db 没有实现
  • 原文地址:https://www.cnblogs.com/hechunhua/p/3056436.html
Copyright © 2011-2022 走看看