htaccess mod_deflate和mod_include与JS文件

时间:2018-02-23 07:57:21

标签: javascript .htaccess mod-deflate mod-include

我使用mod_deflate压缩我的(html | css | js | xml | php | txt)文件。 (没有任何问题地工作)

我还将我的CSS / JS脚本与mod_include模块结合起来以保存请求... 两者都运作良好......但它们没有压缩。

使用我的组合CSS文件,我使用Outputfilter DEFLATE,它与Include MOD一起使用,但是使用我的组合JS文件它不起作用。

如果我使用它Include Mod不起作用它会响应组合JS文件的原始包含内容:

htaccess的

<IfModule mod_deflate.c>
<FilesMatch "\\.(html|css|js|xml|php|txt)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>

 <IfModule mod_include.c>
    <FilesMatch "\.combined\.js$">
        Options +Includes
        AddOutputFilterByType INCLUDES application/javascript application/json
        SetOutputFilter INCLUDES
        SetOutputFilter DEFLATE
    </FilesMatch>
    <FilesMatch "\.combined\.css$">
        Options +Includes
        AddOutputFilterByType INCLUDES text/css
        SetOutputFilter INCLUDES
        SetOutputFilter DEFLATE
    </FilesMatch>
 </IfModule>

输出.combined.js:

<!--#include file="cloudzoom/cloud-zoom.1.0.2.min.js" -->

<!--#include file="supersized/supersized.3.2.7.min.js" -->
<!--#include file="supersized/supersized.shutter.min.js" -->

知道它是如何工作的,或者我自己压缩每个文件?

1 个答案:

答案 0 :(得分:0)

好的,我找到了一个很好的解决方案,它有效的htaccess:

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript


 <IfModule mod_include.c>
    <FilesMatch "\.combined\.js$">
        Options +Includes
        AddOutputFilterByType INCLUDES application/javascript application/json
        SetOutputFilter INCLUDES
    </FilesMatch>
    <FilesMatch "\.combined\.css$">
        Options +Includes
        AddOutputFilterByType INCLUDES text/css
        SetOutputFilter INCLUDES
    </FilesMatch>
 </IfModule>