Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. RewriteEngine on
  2. RewriteRule ^static/.+.(js|ico|gif|jpg|jpeg|png|css|swf)$ compress.php [NC]
  3.  
  4. <?php
  5.  
  6. $basedir = realpath( dirname($_SERVER['SCRIPT_FILENAME']) );
  7. $file = realpath( $basedir . $_SERVER["REQUEST_URI"] );
  8.  
  9. if( !file_exists($file) && strpos($file, $basedir) === 0 ) {
  10. header("HTTP/1.0 404 Not Found");
  11. print "File does not exist.";
  12. exit();
  13. }
  14.  
  15. $components = split('.', basename($file));
  16. $extension = strtolower( array_pop($components) );
  17.  
  18. switch($extension)
  19. {
  20. case 'css':
  21. $mime = "text/css";
  22. break;
  23. default:
  24. $mime = "text/plain";
  25. }
  26.  
  27. header( "Content-Type: " . $mime );
  28. readfile($file);
  29.  
  30. $basedir = realpath( dirname($_SERVER['SCRIPT_FILENAME']) );
  31. $file = realpath( $basedir . $_SERVER["REQUEST_URI"] );
  32.  
  33. <Directory /data/www/path/to/some/site/js/>
  34. AddHandler application/x-httpd-php .js
  35. php_value auto_prepend_file gzip-js.php
  36. php_flag zlib.output_compression On
  37. </Directory>
  38. <Directory /data/www/path/to/some/site/css/>
  39. AddHandler application/x-httpd-php .css
  40. php_value auto_prepend_file gzip-css.php
  41. php_flag zlib.output_compression On
  42. </Directory>
  43.  
  44. <?php
  45. header("Content-type: text/javascript; charset: UTF-8");
  46. ?>
  47.  
  48. <?php
  49. header("Content-type: text/css; charset: UTF-8");
  50. ?>
  51.  
  52. $p = 'path/to/css/file'
  53. $i = stat($p);
  54. if ($_SERVER['HTTP_IF_MODIFIED_SINCE']){
  55. $imd = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
  56. if ( ($imd > 0) && ($imd >= $i['mtime'])){
  57. header('HTTP/1.0 304 Not Modified');
  58. header('Expires:');
  59. header('Cache-Control:');
  60. header('Last-Modified: '.date('r', $i['mtime']));
  61. exit;
  62. }
  63. }
  64. header('Last-Modified: '.date('r', $i['mtime']));
  65. header('Content-Type: text/css');
  66. header('Content-Length: '.filesize($p));
  67. header('Cache-Control:');
  68. header('Pragma:');
  69. header('Expires:');
  70. readfile($p);
  71.  
  72. gzip -c styles.css > styles-gzip.css
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement