昨天同事說 js 用 php 的 gzencode 壓縮後,會變亂碼。

所以就看了一下。

程式如下:

    header('Content-type: text/javascript');
    header('Vary: Accept-Encoding');
    header('Expires: '.gmdate('D, d M Y H:i:s', time() + 3600).' GMT');
    header('Content-Encoding: gzip');
    
    $str = file_get_contents('js/_util/jquery-1.3.2.min.js');
    $str = gzencode($str); 
    echo $str;

查了一下,原來是在 php.ini 就已經設定了 zlib.output_compression = On。

當設定了 zlib.output_compression = On 又在程式中使用 gzencode

這樣子,輸出就會變成亂碼了。

所以簡單的作法,就是【將程式中的 gzencode 拿掉】即可。

// $str = gzencode($str); 

因為已經在 php.ini 設定好要 compression 了。

拿掉後,結果就正常了。

 

PS.

雖然 Lighttpd 中也有設定

compress.filetype          = ("text/plain", "text/html", "text/css", "text/javascript" )

但這個是跟 Lighttpd 沒關系的,因為是從 PHP 去吐的。所以是跟 php.ini 設定檔有關。

在這裡做個記錄。

 

arrow
arrow
    全站熱搜

    Ching-Wei 發表在 痞客邦 留言(0) 人氣()