php minify 下载,lib/Minify/Build.php · Gitee 极速下载/minify - Gitee.com

Minify_Build类用于管理一组Minify源文件的最后修改时间,以便于设置远期Expires头进行缓存优化。它能生成带有时间戳的URI,支持强制使用ampersand。在配置文件中定义源文件组,然后在HTML生成时创建对应的Minify_Build对象,通过Minify::serve()服务这些组,并设置过期时间。这个类是提高静态资源加载效率的一种手段。
摘要由CSDN通过智能技术生成

/**

* Class Minify_Build

* @package Minify

*/

/**

* Maintain a single last modification time for a group of Minify sources to

* allow use of far off Expires headers in Minify.

*

*

* // in config file

* $groupSources = array(

* 'js' => array('file1.js', 'file2.js')

* ,'css' => array('file1.css', 'file2.css', 'file3.css')

* )

*

* // during HTML generation

* $jsBuild = new Minify_Build($groupSources['js']);

* $cssBuild = new Minify_Build($groupSources['css']);

*

* $script = "";

* $link = "";

*

* // in min.php

* Minify::serve('Groups', array(

* 'groups' => $groupSources

* ,'setExpires' => (time() + 86400 * 365)

* ));

*

*

* @package Minify

* @author Stephen Clay

*/

class Minify_Build

{

/**

* Last modification time of all files in the build

*

* @var int

*/

public $lastModified = 0;

/**

* String to use as ampersand in uri(). Set this to '&' if

* you are not HTML-escaping URIs.

*

* @var string

*/

public static $ampersand = '&';

/**

* Get a time-stamped URI

*

*

* echo $b->uri('/site.js');

* // outputs "/site.js?1678242"

*

* echo $b->uri('/scriptaculous.js?load=effects');

* // outputs "/scriptaculous.js?load=effects&amp1678242"

*

*

* @param string $uri

* @param boolean $forceAmpersand (default = false) Force the use of ampersand to

* append the timestamp to the URI.

* @return string

*/

public function uri($uri, $forceAmpersand = false)

{

$sep = ($forceAmpersand || strpos($uri, '?') !== false) ? self::$ampersand : '?';

return "{$uri}{$sep}{$this->lastModified}";

}

/**

* Create a build object

*

* @param array $sources array of Minify_Source objects and/or file paths

*

*/

public function __construct($sources)

{

$max = 0;

foreach ((array)$sources as $source) {

if ($source instanceof Minify_Source) {

$max = max($max, $source->getLastModified());

} elseif (is_string($source)) {

if (0 === strpos($source, '//')) {

$source = $_SERVER['DOCUMENT_ROOT'] . substr($source, 1);

}

if (is_file($source)) {

$max = max($max, filemtime($source));

}

}

}

$this->lastModified = $max;

}

}

一键复制

编辑

Web IDE

原始数据

按行查看

历史

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值