0

在我们的(更新的?迁移的)共享托管服务器上 GZipping 文件时会出现一个奇怪的问题。

检查包含文件夹中具有完全相同内容(php 代码)的这两个相同文件,目的是从各种源 cdd 文件收集、缩小和生成单个 Gzipped css 文件。现在,以 php 结尾的文件似乎可以很好地被 GZipped,但是以扩展名 css 和 js 结尾的文件还没有被 GZipped.../_inc/

/_inc/all.css(24 kbyte,扩展不会让自己 Gzipped)
/_inc/allcss.php(5 kbyte!扩展会让自己 Gzipped)

将扩展名从 css 更改为 php 会使文件如您所见压缩,但浏览器仍然更喜欢 css 扩展名以获得最佳缓存...

Q:为什么只有以php结尾的文件被压缩,而以css和js扩展名结尾的php文件不被压缩?如何为 css 和 js 扩展实现 Gzipping?如何将主要的 .htacces 或 php.ini 也设置为 Gzip 所有 .php、.css、.js 文件?


/.htaccess (用于压缩的根 .htaccess 文件部分)

## interpreted extensions as php
AddType application/x-httpd-php .php
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
#AddType text/css css
#AddType text/javascript js

## compress speficic filetypes BUTTTT doesn't work anymore since server upgrade!
## with or without the code below the result is the same!
<IfModule mod_deflate.c>
<FilesMatch "\.(js|css|eot|ttf|svg|xml|php|txt)$">
    SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>

/_inc/.htaccess (将 css 和 js 文件解释为 php 文件的.htacces 文件)

AddType application/x-httpd-php-cgi .js .css
Action application/x-httpd-php-cgi /cgi-php/php-cgi

php.ini (来自运行 PHP 5.3.28 的 Apache 服务器)

session.gc_maxlifetime = 1440
session.name = PHPSESSID
session.save_handler = files
session.serialize_handler = php
zlib.output_compression = On
zlib.output_handler = ob_gzhandler
allow_call_time_pass_reference = 
implicit_flush = Off
4

0 回答 0