Php 组合css和js文件+;css图像
我正在使用combine.php,它看起来不错,但我想知道是否有解决我的问题的方法 我现在有更少的脚本和链接标签,用于我的资源,它们看起来和工作方式与预期的一样Php 组合css和js文件+;css图像,php,javascript,css,.htaccess,Php,Javascript,Css,.htaccess,我正在使用combine.php,它看起来不错,但我想知道是否有解决我的问题的方法 我现在有更少的脚本和链接标签,用于我的资源,它们看起来和工作方式与预期的一样 <script type="text/javascript" src="http://path/to/server/javascript/libjs/jqueryui/1.8/development-bundle/ui/minified/jquery.ui.core.min.js,libjs/jqueryui/1.8/develo
<script type="text/javascript" src="http://path/to/server/javascript/libjs/jqueryui/1.8/development-bundle/ui/minified/jquery.ui.core.min.js,libjs/jqueryui/1.8/development-bundle/ui/minified/jquery.ui.widget.min.js,libjs/jqueryui/1.8/development-bundle/ui/minified/jquery.ui.datepicker.min.js,libjs/plugins/cluetip/1.0.6/jquery.cluetip.js,libjs/plugins/cluetip/1.0.6/lib/jquery.hoverIntent.js,libjs/plugins/cluetip/1.0.6/lib/jquery.bgiframe.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://path/to/server/css/libjs/jqueryui/1.8/development-bundle/themes/base/jquery.ui.core.css,libjs/jqueryui/1.8/development-bundle/themes/base/jquery.ui.theme.css,libjs/jqueryui/1.8/development-bundle/themes/base/jquery.ui.datepicker.css,libjs/plugins/cluetip/1.0.6/jquery.cluetip.css" >
我手头的具体罪犯必须处理一个脚本和一个脚本
datepicker的图像具有如下请求URL
http://path/to/server/css/libjs/jqueryui/1.8/development-bundle/themes/base/jquery.ui.core.css,libjs/jqueryui/1.8/development-bundle/themes/base/jquery.ui.theme.css,libjs/jqueryui/1.8/development-bundle/themes/base/jquery.ui.datepicker.css,libjs/plugins/cluetip/1.0.6/images/ui-bg_flat_75_ffffff_40x100.png
其中,图像认为路径来自最后一个包含的脚本(libjs/plugins/cluetip/1.0.6/),而实际上来自较早的脚本(libjs/jqueryui/1.8/development bundle/themes/base/)
我不想将任何外部资源更改为绝对路径。这个问题有解决办法吗?有更好的方法处理这种情况吗?您可以简单地用路径中的其他内容(我在下面的示例中使用
:
)替换/
,然后将其翻译回服务器
例如,代替
http://path/to/server/css/libjs/jqueryui/1.8/development-bundle/themes/base/jquery.ui.core.css,libjs/jqueryui/1.8/development-bundle/themes/base/jquery.ui.theme.css,libjs/jqueryui/1.8/development-bundle/themes/base/jquery.ui.datepicker.css,libjs/plugins/cluetip/1.0.6/jquery.cluetip.css
看起来像
http://path/to/server/css/libjs:jqueryui:1.8:development-bundle:themes:base:jquery.ui.core.css,libjs:jqueryui:1.8:development-bundle:themes:base:jquery.ui.theme.css,libjs:jqueryui:1.8:development-bundle:themes:base:jquery.ui.datepicker.css,libjs:plugins:cluetip:1.0.6:jquery.cluetip.css
无论包含顺序如何,它都将保持路径不变,尽管您仍然需要更改文件中的路径(或移动文件本身),因为每个路径都是相对于
http://path/to/server/css/
。但至少它们不必是绝对的。您可以简单地用路径中的其他内容(我在下面的示例中使用:
)替换/
,然后将其翻译回服务器
例如,代替
http://path/to/server/css/libjs/jqueryui/1.8/development-bundle/themes/base/jquery.ui.core.css,libjs/jqueryui/1.8/development-bundle/themes/base/jquery.ui.theme.css,libjs/jqueryui/1.8/development-bundle/themes/base/jquery.ui.datepicker.css,libjs/plugins/cluetip/1.0.6/jquery.cluetip.css
看起来像
http://path/to/server/css/libjs:jqueryui:1.8:development-bundle:themes:base:jquery.ui.core.css,libjs:jqueryui:1.8:development-bundle:themes:base:jquery.ui.theme.css,libjs:jqueryui:1.8:development-bundle:themes:base:jquery.ui.datepicker.css,libjs:plugins:cluetip:1.0.6:jquery.cluetip.css
无论包含顺序如何,它都将保持路径不变,尽管您仍然需要更改文件中的路径(或移动文件本身),因为每个路径都是相对于
http://path/to/server/css/
。但至少它们不必是绝对的。好吧,我就是这么做的。由于combine.php文件为Etag头创建了一个压缩缓存文件,该文件具有唯一的名称,因此我认为在创建缓存文件时,可以动态地将图像路径更新为绝对路径。因此,我稍微修改了脚本,将相对路径重写为绝对路径,这样我就可以保持任何新的/更新的插件不变,并得到我需要的最终结果
我的重写将combine.php文件的以下部分包括在内:
while (list(, $element) = each($elements)) {
$path = realpath($base . '/' . $element);
$contents .= "\n\n" . file_get_contents($path)
}
(注意,$glmBaseUrl是为该脚本所在的服务器动态创建的url)
好吧,我就是这么做的。由于combine.php文件为Etag头创建了一个压缩缓存文件,该文件具有唯一的名称,因此我认为在创建缓存文件时,可以动态地将图像路径更新为绝对路径。因此,我稍微修改了脚本,将相对路径重写为绝对路径,这样我就可以保持任何新的/更新的插件不变,并得到我需要的最终结果 我的重写将combine.php文件的以下部分包括在内:
while (list(, $element) = each($elements)) {
$path = realpath($base . '/' . $element);
$contents .= "\n\n" . file_get_contents($path)
}
(注意,$glmBaseUrl是为该脚本所在的服务器动态创建的url)