2016-04-19 77 views
0

我想創建一個動態的CSS。我在每個CSS規則中追加一個變量。我已經嘗試使用cookie,session和get方法獲取該變量,但它的工作原理與10次中的1次相同。在css文件中使用php代碼創建動態css dosen't工程每次..有時動態css不加載只有靜態規則在該css被加載

CSS文件(component.min.css):

<?php 
header('Content-type: text/css; charset: UTF-8'); 
header('Cache-control: must-revalidate'); 
$appVar = ""; 

if(!empty($_COOKIE["_adl_appVar"])) 
{ 
    $appVar = $_COOKIE['_adl_appVar']; 
} 
elseif(!empty($_SESSION['_adl_appVar'])) 
{ 
    $appVar = $_SESSION['_adl_appVar']; 
} 
?> 

/* General styles for the modal */ 

/* 
Styles for the html/body for special modal where we want 3d effects 
Note that we need a container wrapping all content on the page for the 
perspective effects (not including the modals and the overlay). 
*/ 
.<?php echo $appVar ?>abs<?php echo $appVar ?>-perspective, 
.<?php echo $appVar ?>abs<?php echo $appVar ?>-perspective body { 
    height: 100%; 
    overflow: hidden; 
} 

.<?php echo $appVar ?>abs<?php echo $appVar ?>-perspective body { 
    background: #fff; 
    -webkit-perspective: 600px; 
    -moz-perspective: 600px; 
    perspective: 600px; 
} 
.container { 
    min-height: 100%; 
} 

.htaccess文件

<IfModule mod_rewrite.c> 
    RewriteEngine On 
</IfModule> 
<FilesMatch "^.*?component.min.*?$"> 
SetHandler php5-script 
</FilesMatch> 

比方說,上述情況下輸出將是這個CSS

渲染CSS(不正確)

.container { 
    min-height: 100%; 
} 

Whil e如果它應該呈現這樣的: -

/* General styles for the modal */ 

/* 
Styles for the html/body for special modal where we want 3d effects 
Note that we need a container wrapping all content on the page for the 
perspective effects (not including the modals and the overlay). 
*/ 
.9d94584f3c1af62a2078da0ec45702baabs9d94584f3c1af62a2078da0ec45702ba-perspective, 
.9d94584f3c1af62a2078da0ec45702baabs9d94584f3c1af62a2078da0ec45702ba-perspective body { 
    height: 100%; 
    overflow: hidden; 
} 

.9d94584f3c1af62a2078da0ec45702baabs9d94584f3c1af62a2078da0ec45702ba-perspective body { 
    background: #fff; 
    -webkit-perspective: 600px; 
    -moz-perspective: 600px; 
    perspective: 600px; 
} 

.container { 
    min-height: 100%; 
} 

我加載使用jQuery的css文件(請參見下文): -

$("head").append('<link rel="stylesheet" href="path/to/css/component.min.css" id="component-css" type="text/css" media= "screen" />'); 
+0

http://stackoverflow.com/questions/11474345/force-browser-to-refresh-css-javascript-etc – user3791775

+0

要驗證這是不是確實是一個緩存的問題嘗試做一個捲曲或wget(或相當於)從命令行查看返回的內容。 – apokryfos

+0

爲什麼你需要首先動態生成這樣一個奇怪的類名?我認爲在(部分)動態創建的CSS資源中輸出它可能是一個相當糟糕的主意;將它直接放入HTML代碼中的'