サーバーがApacheのdeflateおよびgzipモジュールをサポートしていないと想像してください。この場合、データを圧縮する方法はいくつかあります。
これを行うには、Apacheリライトモジュールとphpgzip拡張機能を使用します。
$ _SERVER ['REQUEST_URI']を取得し、そのコンテンツを取得し、ヘッダーを設定し、コンテンツをファイルとして圧縮およびフラッシュするために、gzip.phpという名前のファイルを1つ作成しました。
すべてのファイルの拡張子を保持したので、apacheはファイルタイプを保持します。
これらの行を.htaccessに追加しました。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^((.*)\.(js|css))$ gzip.php [L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
これらのヘッダーをファイルに追加しました。
$src = $_SERVER['REQUEST_URI'];
// seconds, minutes, hours, days
$expires = 60*60*24*14;
ob_start();
ob_implicit_flush(0);
header("Pragma: public");
header("Cache-Control: maxage=".$expires);
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT');
// Then do everything you want to do on the page
$path = PUBLIC_DIR . $src;
$info = pathinfo($path);
$ext = strtolower($info['extension']);
include_once 'Entezar/File.php';
$mimeType = Entezar_File::getMimeType($path);
header("Content-type: $mimeType");
if (file_exists($path) && in_array($ext, array('js', 'css'))) {
$fs = stat($path);
header("Etag: ".sprintf('"%x-%x-%s"', $fs['ino'], $fs['size'],base_convert(str_pad($fs['mtime'],16,"0"),10,16)));
echo file_get_contents($path);
}
unset($path, $src, $info, $ext);
私の問題は、phpに沿ってapache rewriteモジュールを使用してコンテンツを圧縮すると、FireFoxがファイル(cssまたはjs)をキャッシュからまったくロードしないことです。誰か助けてもらえますか?