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;
    }
    ?>

    文件下载

  • 相关阅读:
    关于ArcGis for javascrept查询ArcGis server图层信息的方式
    Elasticsearch教程之基础概念
    C# 将日期转换成中文格式
    .Net 自定义Excel模板导出数据
    JavaScript判断浏览器类型
    简单的json传送数据
    Oracle替换临时表空间
    Python多线程循环
    crontab执行不生效-【问题篇】
    Python将MySQL表数据写入excel
  • 原文地址:https://www.cnblogs.com/hechunhua/p/3056436.html
Copyright © 2011-2022 走看看