【发布时间】:2013-05-28 19:22:17
【问题描述】:
我主持了一个 JavaScript 游戏,它基本上由一个 .html 和一个 .data 文件组成。如果我用 gzip 压缩它们,它们的大小会缩小到 25%。所以我想这样做。
我不是 100% 确定,但我认为使用 mod_gzip 或 mod_deflate 会即时压缩,因为内容不会改变,所以一直在浪费 CPU 时间。
所以我想预编译内容。因此,我在未压缩文件旁边放了一个.gz,并将重写规则放在.htaccess中:
RewriteEngine on
# If client accepts compressed files
RewriteCond %{HTTP:Accept-Encoding} gzip
# and if compressed file exists
RewriteCond %{REQUEST_FILENAME}.gz -f
# send .html.gz instead of .html
RewriteRule ^(.+)\.(html|css|js|data)$ $1.$2.gz [T=text/$2,E=GZIP:gzip,L]
Header set Content-Encoding gzip env=GZIP
重定向工作正常,我可以请求 game.html 并实际获得传递的 game.html.gz。但是,浏览器不只是显示它。相反,它会询问我将文件保存在哪里。我该如何解决?或者也许还有其他方法可以实现我的目标?
【问题讨论】:
-
似乎 apache 不尊重 T 修饰符。服务器实际返回什么内容类型?
-
我很难找到答案。当 ff 想要保存文件时,Firebug 不报告 Content-type - 或者我不知道如何查看它。
标签: javascript apache .htaccess mod-rewrite http-compression