memo.xight.org

日々のメモ

JavaScriptファイルを圧縮して読み込ませる

Summary

JavaScriptファイル自体を gzip で圧縮して読み込ませれば良い.
<script type="text/javascript" src="prototype.js.gz"></script>


圧縮されたJavaScriptがSafariで読み込めない問題

圧縮したJavaScriptファイルの拡張子を .jgz とし,
mod_rewriteで .jgz へのアクセスを .js にリダイレクト.

RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ".*Safari.*" [OR]
RewriteCond %{HTTP:Accept-Encoding} !gzip
RewriteRule (.*)\.jgz$ $1\.js [L]

AddType "text/javascript;charset=UTF-8" .jgz
AddEncoding gzip .jgz


Reference

亜細亜の蛾 - 2006-11-16 - prototype.jsを10KBにする方法
http://asiamoth.com/mt/archives/2006-11/16_2331.php

こぶたのラッパ : 世界の片隅で.jgzと言ってみる
http://smil.exblog.jp/4650470/