Autor | Zpráva | ||
---|---|---|---|
Fisak Profil * |
#1 · Zasláno: 28. 12. 2011, 18:51:11 · Upravil/a: Fisak
Zdravím... nikdy jsem Gzip nedělal ale slyšel jsem že to je pro web lepší jelikož to ušetří až 30% načtených dat.. poradil by mi někdo jak na to ?? Rád bych Gzip zapnul buďto přes htaccess přes mod_deflate a nebo když server mod_deflate nemá tak aby se automaticky zapínalo jinak např. přes PHPčko.... předem díky za odpověď...
našel sem článek s kódem ale nevim jestli je to dobře... <IfModule mod_deflate.c> SetOutputFilter DEFLATE <IfModule mod_setenvif.c> # Netscape 4.x has some problems... BrowserMatch ^Mozilla/4 gzip-only-text/html # Netscape 4.06-4.08 have some more problems BrowserMatch ^Mozilla/4\.0[678] no-gzip # MSIE masquerades as Netscape, but it is fine # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48 # the above regex won't work. You can use the following # workaround to get the desired effect: BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html # Don't compress images SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary </IfModule> <IfModule mod_headers.c> # Make sure proxies don't deliver the wrong content Header append Vary User-Agent env=!dont-vary </IfModule> </IfModule> do htaccess sem tedy přidal: <IfModule mod_gzip.c> mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^text\.* mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_exclude mime ^image\.* mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* </IfModule> <IfModule mod_deflate.c> SetOutputFilter DEFLATE <IfModule mod_setenvif.c> # Netscape 4.x has some problems... BrowserMatch ^Mozilla/4 gzip-only-text/html # Netscape 4.06-4.08 have some more problems BrowserMatch ^Mozilla/4\.0[678] no-gzip # MSIE masquerades as Netscape, but it is fine # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48 # the above regex won't work. You can use the following # workaround to get the desired effect: BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html # Don't compress images SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary </IfModule> <IfModule mod_headers.c> # Make sure proxies don't deliver the wrong content Header append Vary User-Agent env=!dont-vary </IfModule> </IfModule> <FilesMatch "\.(eot|woff|ttf|svg)$"> Header set Expires "Thu, 15 Apr 2020 20:00:00 GMT" Header set Cache-Control "public, max-age=2592000" </FilesMatch> <FilesMatch ".(js|css|txt)$"> Header set Cache-Control "public, max-age=604800" </FilesMatch> <FilesMatch ".(flv|swf|ico|gif|jpg|jpeg|png)$"> Header set Cache-Control "public, max-age=2592000" </FilesMatch> <FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$"> Header unset Cache-Control </FilesMatch> |
||
Nox Profil |
#2 · Zasláno: 28. 12. 2011, 19:51:18
Podívej se na hlavičky, např. přes Firebug (FF addon), mohl by tam být záznam o kompresi...ale jednoduše si můžeš prostě zkusit toto vypnout a zapnout a měla by být vidět značná změna ve velikostech textových souborů
Fallback na PHP můžeš udělat přes SetEnv pokud je deflate přítomný a potom to kontrolovat v PHP, asi http://php.net/manual/en/function.getenv.php |
||
Fisak Profil * |
#3 · Zasláno: 28. 12. 2011, 19:54:44
počkat na začátku celé stránky sem umístil
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ob_start("compress"); ob_end_flush(); |
||
Časová prodleva: 12 let
|
0