PHP

2012-08-06 5 views
8

के साथ सीएसएस को संपीड़ित और कैशिंग करना मैं वर्तमान में अपनी सीएसएस फ़ाइलों के लिए एक संपीड़न विधि प्राप्त करने की कोशिश कर रहा हूं। मैं मूल रूप से उसी तरह की प्रतिलिपि बना रहा हूं जो मैं अपनी जेएस फाइलों के लिए करता हूं, लेकिन यह काम नहीं कर रहा है। मैंने फायरबग टूल के साथ जांच की, लेकिन कोई सीएसएस लोड नहीं किया जा रहा है।PHP

मैं css.php कैसे कॉल कर सकता हूं जो तब संपीड़ित सीएसएस फ़ाइलों को कॉल करेगा?

जे एस के साथ कार्य करना कोड, फ़ाइल scripts.php है (मैं .js विस्तार निर्दिष्ट नहीं किया है):

<script type="text/javascript" src="js/scripts.php?build=123&load=foo,bar"></script> 

मैं अपने सीएसएस फ़ाइलों के लिए भी ऐसा ही करना चाहता था:

<link href="styles/css.php?build=123&load=foo,bar/jquery-ui-1.8rc2.custom" type="text/css"> 

css.php संपीड़न करना है:

<?php 
error_reporting(E_ERROR); 
// see http://web.archive.org/web/20071211140719/http://www.w3.org/2005/MWI/BPWG/techs/CachingWithPhp 
// $lastModifiedDate must be a GMT Unix Timestamp 
// You can use gmmktime(...) to get such a timestamp 
// getlastmod() also provides this kind of timestamp for the last 
// modification date of the PHP file itself 

function cacheHeaders($lastModifiedDate) { 
    if ($lastModifiedDate) { 
     if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $lastModifiedDate) { 
      if (php_sapi_name()=='CGI') { 
       Header("Status: 304 Not Modified"); 
      } else { 
       Header("HTTP/1.0 304 Not Modified"); 
      } 
      exit; 
     } else { 
      $gmtDate = gmdate("D, d M Y H:i:s \G\M\T",$lastModifiedDate); 
      header('Last-Modified: '.$gmtDate); 
     } 
    } 
} 

// This function uses a static variable to track the most recent 
// last modification time 
function lastModificationTime($time=0) { 
    static $last_mod ; 
    if (!isset($last_mod) || $time > $last_mod) { 
     $last_mod = $time ; 
    } 
    return $last_mod ; 
} 

lastModificationTime(filemtime(__FILE__)); 
cacheHeaders(lastModificationTime()); 
header("Content-type: text/css; charset: UTF-8"); 

ob_start ("ob_gzhandler"); 

foreach (explode(",", $_GET['load']) as $value) { 
    if (is_file("$value.css")) { 
     $real_path = mb_strtolower(realpath("$value.css")); 
     if (strpos($real_path, mb_strtolower(dirname(__FILE__))) !== false ||strpos($real_path, mb_strtolower(dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'modules'.DIRECTORY_SEPARATOR)) !== false) { 
      lastModificationTime(filemtime("$value.css")); 
      include("$value.css"); echo "\n"; 
     } 
    } 
} 
?> 

उत्तर

3

आप <link> टैग से rel="stylesheet" विशेषता खो रहे हैं। इसके अलावा, कोड ठीक दिखता है।

आप प्रश्न को देखना और here का उत्तर देना चाहेंगे।

+1

ओह वाह, इस तरह के एक महत्वपूर्ण विस्तार से चूक गए। धन्यवाद! – CodingWonders90

1

minify आज़माएं। यह वर्ग संकुचित और जेएस और सीएसएस कैश।

संबंधित मुद्दे

 संबंधित मुद्दे