系統可以支援CSS,JS多個載入

來源:互聯網
上載者:User

我們經常看到大網站支援逗號分隔的CSS,JS載入,例如:

<link type="text/css" rel="stylesheet" href="http://s.juancdn.com/juanpi/css/??base.css,globale.css,md-business.css,pg-enroll.css,pg-manage.css,pg-my-account.css,alert.css?ts=1234"/><script src="http://s.juancdn.com/common/js/??jquery.min.js,base.js?ts=1234"></script>
如下示解決辦法:

1、修改APACHE的設定檔httpd.conf並重啟,如下建立了s.juancdn.com的綁定並支援重寫

<VirtualHost *:80>
    DocumentRoot "D:/wamp/www/static"
    ServerName s.juancdn.com
<Directory "D:/wamp/www/static">
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>
</VirtualHost>

2、根目錄添加.htaccess

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} ^(.+)$
RewriteRule ^(.*) /index.php [QSA,PT,L]
</IfModule>

3、建立入口檔案index.php

<?php
$r = $_SERVER['REQUEST_URI'];
preg_match_all("/\/(.*?)\/?\?\?(.*?)(\?.*)/",$r,$matches);
if(!empty($matches)&&!empty($matches[1][0])&&!empty($matches[2][0])){
    $_GET['b'] = $matches[1][0];
    $_GET['f'] = $matches[2][0];
}else{
    die("bad request");
}
if(!empty($matches)&&!empty($matches[3][0])){
    parse_str($matches[3][0]);
}
include_once("min/index.php");

4、修改設定檔min/config.php

修改如下一行參數為存在的地址:

$min_cachePath = 'c:\\WINDOWS\\Temp';

5、修改程式的設定檔conf/test.php【這個不知道需要不】

加入:

'.css?'=>'.css',//前端靜態檔案路徑
 '.js?'=>'.js',//前端靜態檔案路徑

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.