मैं PHP में इस का उपयोग कर रहे हैं - आप प्रेरणा के लिए इसका इस्तेमाल करते हैं हो सकता है:
<?
$test_server = $_SERVER['SERVER_NAME'] == "127.0.0.1" || $_SERVER['SERVER_NAME'] == "localhost" || substr($_SERVER['SERVER_NAME'],0,3) == "192";
function caching_headers ($timestamp) {
global $test_server;
if (!$test_server) {
$gmt_mtime = gmdate('r', $timestamp);
if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $gmt_mtime) {
header('HTTP/1.1 304 Not Modified');
exit();
}
}
header('Last-Modified: '.$gmt_mtime);
}
}
header ("Content-Type: application/javascript; charset=utf-8");
include ($_SERVER['DOCUMENT_ROOT']."/media/js/jsmin.php");
$libs = explode("|",$_GET['libs']);
$uniq_string = "";
foreach ($libs as $lib) {
$uniq_string .= filemtime($_SERVER['DOCUMENT_ROOT']."/media/js/$lib.js");
}
$hash = md5($uniq_string);
$cachefile = $_SERVER['DOCUMENT_ROOT']."/cache/".$hash.".js";
if(file_exists($cachefile)) {
$last_mod = filemtime($cachefile);
caching_headers ($last_mod);
include($cachefile);
echo "//Cached on ".gmdate('r', $last_mod)." to ".$hash;
exit;
} else {
$combined = "";
foreach ($libs as $lib) {
if (substr($lib, strlen($lib)-3, 3) == "min") {
$combined .= file_get_contents($_SERVER['DOCUMENT_ROOT']."/media/js/$lib.js")."\n";
} else {
$combined .= JSMin::minify(file_get_contents($_SERVER['DOCUMENT_ROOT']."/media/js/$lib.js"))."\n";
}
}
$fp = fopen($cachefile, 'w');
fwrite($fp, $combined);
fclose($fp);
$last_mod = filemtime($cachefile);
caching_headers ($last_mod);
include($cachefile);
echo "//Cached on ".gmdate('r', $last_mod)." to ".$hash;
}
?>
JSMin-php के साथ।
मैं तो का उपयोग करें:
<script src="/media/js/combined.php?libs=jquery-1.5.1.min|behaviour|jquery.form"></script>
अपने पृष्ठों में
।
यह कैश की गई मिनीफ़ोन फ़ाइल को/कैश/पर संग्रहीत करता है, इसलिए सुनिश्चित करें कि यदि आप इसे आजमा रहे हैं तो फ़ोल्डर मौजूद है।
स्रोत
2011-05-12 20:05:20
यह आपके सर्वर की तरफ तैनाती विधि में एक उपकरण बन जाएगा। एकीकरण उपकरण आपके सर्वर (PHP, .NET, ruby, आदि) पर निर्भर करता है – Raynos
हम जवार का उपयोग करते हैं। विकास में हमने डीबग सही सेट किया है और उत्पादन में हमने गलत डिबग सेट किया है। जब हम गलत के रूप में डीबग सेट करते हैं, तो स्क्रिप्ट और अन्य संसाधन क्लाइंट में डिकंप्रेस हो जाएंगे, ताकि आप अपना कोड देख सकें। –
मेरे मामले में सर्वर पक्ष एक विकल्प नहीं है। –