TheQn Posted August 10, 2011 Report Share Posted August 10, 2011 (edited) kr4 nesaprotu kur kluda combine.php negrib .css faili apvienoties viena faila, bet .js apvienojas viena faila un compressojas, kur var but kluda. combine.php <?php header("Vary: Accept-Encoding"); error_reporting(0); $cache = true; $cachedir = dirname(__FILE__) . '/cache'; $cssdir = dirname(__FILE__) . '../../css/'; $jsdir = dirname(__FILE__) . '../../javascript/'; if (!isset($_GET['files']) or strlen($_GET['files']) == 0) { header('Status: 404 Not Found'); exit(); } if (!file_exists($cachedir)) { mkdir($cachedir); } $type = $_GET['type']; switch ($type) { case 'css': $base = realpath($cssdir); break; case 'javascript': $base = realpath($jsdir); break; default: header("HTTP/1.0 503 Not Implemented"); exit; }; $files = explode(',', $_GET['files']); $types = array_fill(0, sizeof($files), $type); function addExtension($file, $type) { if ($type == 'javascript' && substr($file, -3) !== '.js') { $file .= '.js'; } elseif ($type == 'css' && substr($path, -4) !== '.css') { $file .= '.css'; } return $file; } $files = array_map('addExtension', $files, $types); $lastmodified = 0; foreach ($files as $file) { $path = realpath($base.'/'.$file); if (!file_exists($path)) { header("HTTP/1.0 404 Not Found"); exit; } $lastmodified = max($lastmodified, filemtime($path)); } $md5 = md5($_GET['files']); $hash = $lastmodified . '-' . $md5; header("ETag: \"" . $hash . "\""); if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) == '"' . $hash . '"') { header("HTTP/1.0 304 Not Modified"); header('Content-Length: 0'); exit; } else { $gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'); $deflate = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate'); $encoding = $gzip ? 'gzip' : ($deflate ? 'deflate' : 'none'); if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Opera') && preg_match('/^Mozilla\/4\.0 \(compatible; MSIE ([0-9]\.[0-9])/i', $_SERVER['HTTP_USER_AGENT'], $matches)) { $version = floatval($matches[1]); if ($version < 6) $encoding = 'none'; if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) $encoding = 'none'; } if ($cache) { $cachefile = 'cache-' . $md5 . '.' . (($type === 'css') ? 'css' : 'js') . (($encoding != 'none') ? '.' . $encoding : ''); if (file_exists($cachedir . '/' . $cachefile) && $lastmodified < filemtime($cachedir . '/' . $cachefile)) { if ($encoding != 'none') { header("Content-Encoding: " . $encoding); } header("Content-Type: text/" . $type); header("Content-Length: " . filesize($cachedir . '/' . $cachefile)); readfile($cachedir . '/' . $cachefile); exit; } } $contents = ''; foreach ($files as $file) { $path = realpath($base.'/'.$file); $contents .= file_get_contents($path); } if ($type === 'css') { $contents = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $contents); $contents = str_replace(array("\r", "\n", "\t", ' ', ' '), '', $contents); } else { require ('classes/jsmin.php'); $contents = JSMin::minify($contents); } header("Content-Type: text/" . $type); if (isset($encoding) && $encoding != 'none') { $contents = gzencode($contents, 9, $gzip ? FORCE_GZIP : FORCE_DEFLATE); header("Content-Encoding: " . $encoding); header('Content-Length: ' . strlen($contents)); echo $contents; } else { header('Content-Length: ' . strlen($contents)); echo $contents; } if ($cache) file_put_contents($cachedir . '/' . $cachefile, $contents); } ?> .htaccess RewriteEngine On RewriteRule ^css/(.*\.css)$ /engine/combine.php?type=css&files=$1 RewriteRule ^javascript/(.*\.js)$ /engine/combine.php?type=javascript&files=$1 Index.php <link rel="stylesheet" type="text/css" href="css/reset.css,global.css" /> <script type="text/javascript"> (function() { var ssync = document.createElement('script'); ssync.type = 'text/javascript'; ssync.async = true; ssync.src = 'javascript/jquery.js,common.js'; var xsync = document.getElementsByTagName('script')[0]; xsync.parentNode.insertBefore(ssync,xsync); } )(); </script> Edited August 10, 2011 by TheQn Quote Link to comment Share on other sites More sharing options...
TheQn Posted August 10, 2011 Author Report Share Posted August 10, 2011 Up Quote Link to comment Share on other sites More sharing options...
Kaklz Posted August 11, 2011 Report Share Posted August 11, 2011 Manuprāt šis jau saknē nav pareizs domu gājiens. Mēs sen sen atpakaļ mēģinājām šādu sistēmu izmantot, bet tā beigu beigās pārvērtās par mērenu murgu ar visām kešotajām versijām, versiju pacelšanām, utt. Daudz labāks risinājums ir publiski likt jau vienu sapakotu failu un atsevišķus specifiskos failus lādēt atsevišķi. Iedomājies situāciju, kad tev ir teiksim 20 dažādi CSS faili, tu viņus atkarībā no vajadzības kombinē teiksim 400 kombinācijās. Pamaini vienu CSS failu un tev kaut kādā brīdī lietotājiem ir atkal jānovelk 400 dažādas failu kombinācijas, kā rezultātā viss ir slikti. Labāk sapako vienu universālu CSS failu jau pirms likšanas publiskajā vidē un paļaujies uz to, ka pārlūks to iekešos. Būs stipri labāk. Es arī nevaru iedomāties iemeslu, kāpēc reset.css saturs nevarētu atrasties global.css iekšienē. Quote Link to comment Share on other sites More sharing options...
TheQn Posted August 11, 2011 Author Report Share Posted August 11, 2011 (edited) Sis combine scripts comprese css,js failus tikai vienu reizi, un nem no cache folderi kam lietotajam piemeram cache-fwqfqw432423423f4f2f4.js.gzip nu nelade katram lietotajom compress css strada tika ta <link rel="stylesheet" type="text/css" href="/engine/combine.php?type=css&files=reset,global" /> nezinu kapec vins negrib stradat caur .htaccess sada veida RewriteRule ^css/(.*\.css)$ /engine/combine.php?type=css&files=$1 jo es taisu savu cms man vajag tikai so combine.php lai stradatu. man liekas ta problema ir combine.php scripta jo es nevaru atrast so kludu scripta. busu pateicigs kurs atradis kludu un izlabos. Edited August 11, 2011 by TheQn Quote Link to comment Share on other sites More sharing options...
Kaklz Posted August 11, 2011 Report Share Posted August 11, 2011 Sāc ar to, ka skaties, ko tev rāda access vai error log. Quote Link to comment Share on other sites More sharing options...
TheQn Posted August 11, 2011 Author Report Share Posted August 11, 2011 vo ko uzrada access ip - - [11/Aug/2011:14:18:32 +0300] "GET /css/reset.css,global.css HTTP/1.1" 404 20 ip - - [11/Aug/2011:14:18:47 +0300] "GET /css/reset.css,global.css HTTP/1.1" 404 20 ip - - [11/Aug/2011:14:18:50 +0300] "GET /css/reset.css,global.css HTTP/1.1" 404 20 bet nezinu kapec rada 404 ja es ieliku pareizu celu lids css folderim pasa combine.php, un .htaccess bet kludu nevaru atrast. Quote Link to comment Share on other sites More sharing options...
daGrevis Posted August 11, 2011 Report Share Posted August 11, 2011 Fails ar nosaukumu 'reset.css,global.css' eksistē? :P Quote Link to comment Share on other sites More sharing options...
TheQn Posted August 11, 2011 Author Report Share Posted August 11, 2011 ja eksiste Quote Link to comment Share on other sites More sharing options...
briedis Posted August 11, 2011 Report Share Posted August 11, 2011 ja tu atver pārlūkā pats www.lblabla.lv/css/reset.css,global.css tad rādās atbilstošais fails? Quote Link to comment Share on other sites More sharing options...
TheQn Posted August 11, 2011 Author Report Share Posted August 11, 2011 tikai baltu rapu uzrada. Quote Link to comment Share on other sites More sharing options...
briedis Posted August 11, 2011 Report Share Posted August 11, 2011 nu tad ir jāsāk debugot. Skaties, cik tālu tas skripts izpildās un vai vispār viņš tiek izsaukts. Kaut vai ar echo "esmu šeit" ievietošanu dažādās koda vietās... Quote Link to comment Share on other sites More sharing options...
daGrevis Posted August 11, 2011 Report Share Posted August 11, 2011 Kādā sakarā faila nosaukumā Tev ir divi faila nosaukumi, kad atdalīti ar komatu?? Quote Link to comment Share on other sites More sharing options...
TheQn Posted August 11, 2011 Author Report Share Posted August 11, 2011 si koda dala urzrada Here! elseif ($type == 'css' && substr($path, -4) !== '.css') { $file .= '.css'; echo "Here"; } si koda dala neko neuzrada if ($type === 'css') { $contents = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $contents); $contents = str_replace(array("\r", "\n", "\t", ' ', ' '), '', $contents); $contents = str_replace('{ ','{', $contents); $contents = str_replace(' }','}', $contents); $contents = str_replace('; ',';', $contents); $contents = str_replace(', ',',', $contents); $contents = str_replace(' {','{', $contents); $contents = str_replace('} ','}', $contents); $contents = str_replace(': ',':', $contents); $contents = str_replace(' ,',',', $contents); $contents = str_replace(' ;',';', $contents); echo "here"; } lieku echo kur ir apstrada ar css faili. taisiju vel ta var_dump($cssdir);, var_dump($files);, var_dump($file); vispar neko neuzrada. Quote Link to comment Share on other sites More sharing options...
daGrevis Posted August 11, 2011 Report Share Posted August 11, 2011 Tas, ka mainīs ko un kā izvadīsi - neko nedos. :D Tev tagad ir jānoskaidro, kāpēc skripts tajā blokā negrib pildīties. :) Quote Link to comment Share on other sites More sharing options...
TheQn Posted August 11, 2011 Author Report Share Posted August 11, 2011 (edited) kods ir 100% pareizi uzrakstits, es pats nesaprotu kur kluda, es vel meginaju error_reporting(E_ALL) un error_reporting(8191) kludas koda neradas. <pre id="line1">string(18) "C:\AppServ\www/css" </pre> var_dump($types); null uzrada <pre id="line1">string(20) "reset.css,global.css" vis pareizi</pre> Edited August 11, 2011 by TheQn Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.