Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RewriteEngine on
- RewriteRule ^static/.+.(js|ico|gif|jpg|jpeg|png|css|swf)$ compress.php [NC]
- <?php
- $basedir = realpath( dirname($_SERVER['SCRIPT_FILENAME']) );
- $file = realpath( $basedir . $_SERVER["REQUEST_URI"] );
- if( !file_exists($file) && strpos($file, $basedir) === 0 ) {
- header("HTTP/1.0 404 Not Found");
- print "File does not exist.";
- exit();
- }
- $components = split('.', basename($file));
- $extension = strtolower( array_pop($components) );
- switch($extension)
- {
- case 'css':
- $mime = "text/css";
- break;
- default:
- $mime = "text/plain";
- }
- header( "Content-Type: " . $mime );
- readfile($file);
- $basedir = realpath( dirname($_SERVER['SCRIPT_FILENAME']) );
- $file = realpath( $basedir . $_SERVER["REQUEST_URI"] );
- <Directory /data/www/path/to/some/site/js/>
- AddHandler application/x-httpd-php .js
- php_value auto_prepend_file gzip-js.php
- php_flag zlib.output_compression On
- </Directory>
- <Directory /data/www/path/to/some/site/css/>
- AddHandler application/x-httpd-php .css
- php_value auto_prepend_file gzip-css.php
- php_flag zlib.output_compression On
- </Directory>
- <?php
- header("Content-type: text/javascript; charset: UTF-8");
- ?>
- <?php
- header("Content-type: text/css; charset: UTF-8");
- ?>
- $p = 'path/to/css/file'
- $i = stat($p);
- if ($_SERVER['HTTP_IF_MODIFIED_SINCE']){
- $imd = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
- if ( ($imd > 0) && ($imd >= $i['mtime'])){
- header('HTTP/1.0 304 Not Modified');
- header('Expires:');
- header('Cache-Control:');
- header('Last-Modified: '.date('r', $i['mtime']));
- exit;
- }
- }
- header('Last-Modified: '.date('r', $i['mtime']));
- header('Content-Type: text/css');
- header('Content-Length: '.filesize($p));
- header('Cache-Control:');
- header('Pragma:');
- header('Expires:');
- readfile($p);
- gzip -c styles.css > styles-gzip.css
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement