Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php] Gzip w plikach css i javascipt
Forum PHP.pl > Forum > PHP
propage
Mam problem z gzipowniem plikow js i css

używam takiego kodu

  1. Htaaccess
  2.  
  3. RewriteCond %{REQUEST_FILENAME} -f
  4. RewriteRule (.*).(js|css)$ gzip.php?url=$1.$2&type=$2 [L]
  5.  
  6.  
  7.  
  8. gzip.php
  9.  
  10. <?
  11. $file=$_GET['url'];
  12.  
  13. $file_last_modification = filemtime ($file);
  14. $gm_file_last_modification = gmdate ("D, d M Y H:i:s T", $file_last_modification);
  15.  
  16. if ($_SERVER['HTTP_IF_MODIFIED_SINCE'] == $gm_file_last_modification) {
  17.   //header ("HTTP/1.0 304 Not Modified");
  18.   //header ('ETag: "' . md5 ($file . $file_last_modification) . '"');
  19.   //exit;
  20. }
  21. (end (explode ('.', $file)) == 'css') ? header ('Content-type: text/css; charset:UTF-8') : header('Content-type: text/javascript; charset: UTF-8');
  22.  
  23. header ('Last-Modified: ' . $gm_file_last_modification);
  24. header ('ETag: "' . md5 ($file . $file_last_modification) . '"');
  25.  
  26. if (substr_count ($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) {
  27.   $filegz = 'gzipped/' . $file . '.gz';
  28.    
  29.   $makeNewGz = false;
  30.   if (file_exists ($filegz)) {
  31.     $gzip_last_modification = filemtime ($filegz);
  32.     if ($gzip_last_modification + 10 < $file_last_modification) {
  33.       $makeNewGz = true;
  34.     }
  35.   } else {
  36.     $makeNewGz = true;
  37.   }
  38.   if ($makeNewGz === true) {
  39.     $handle = gzopen ($filegz, 'w9');
  40.     gzwrite ($handle, file_get_contents ($file));
  41.     gzclose ($handle);
  42.     chmod ($filegz, 0666);
  43.   }
  44.    header ('Content-Encoding: gzip');
  45.   
  46.    header ('Vary: Accept-Encoding');
  47.    echo file_get_contents ($filegz);
  48.    exit;
  49.   // include($file);
  50. }
  51. else
  52. {
  53.  include($file);
  54. } 
  55. ?>





jednak plik, ktory otrzymuje przegladarka jest zapakowano gzipiem, tak jakby przeglodarka nie otrzymała informacji ze jest to spakowany plik i nie rozpakowywala go

Np:

http://sdtelkom.propage.pl/css/style.css

Co robie nie tak?
szagi3891
Spróbuj może w innej przeglądarce. U mnie się dobrze ten plik wyświetla. Moja przeglądarka dostaje go w spakowanej formie. Stopień kompresji to 4 KB z 19 KB wielkości oryginalnej.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.