如何强制Apache在使用手动$ CSS和JS文件的对$ P-COM pressed GZ文件? [英] How to force Apache to use manually pre-compressed gz file of CSS and JS files?

查看:167
本文介绍了如何强制Apache在使用手动$ CSS和JS文件的对$ P-COM pressed GZ文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的问题。我有webdirectory / CSS 和里面的文件的style.css 。我已经手动gzip压缩这个文件并将其保存为 style.css.gz 。我想,以节省CPU周期不必在每个请求pssed CSS文件COM $ P $。我如何配置Apache寻找这个。广州文件和服务于它,而不是COM pressing 的.css 的文件一遍又一遍?

I have simple question. I have webdirectory /css and inside is file style.css. I have manually gzipped this file and saved it as style.css.gz. I want to save CPU cycles to not have CSS file compressed at each request. How do I configure Apache to look for this .gz file and serve it instead of compressing .css file over and over again ?

请注意:我不想阿帕奇创建。广州文件本身。在我的情况我要创建 .css.gz 手动档 - 使用上的具体要求PHP

Note: I don't want Apache to create .gz file itself. In my scenario I have to create .css.gz file manually - using PHP on specific requests.

推荐答案

一些重写规则应该处理得非常好。

Some RewriteRule should handle that quite well.

在一个Drupal配置文件中,我发现:

In a Drupal configuration file I found:

# AddEncoding allows you to have certain browsers uncompress information on the fly.
AddEncoding gzip .gz

#Serve gzip compressed CSS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.css $1\.css\.gz [QSA]

# Serve gzip compressed JS files if they exist and the client accepts gzip.
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -s
RewriteRule ^(.*)\.js $1\.js\.gz [QSA]

# Serve correct content types, and prevent mod_deflate double gzip.
RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]

这将使工作。你可以把无论是在<目录富/> 部分或.htaccess文件,如果你没有访问到Apache配置,或者,如果你想放慢你的网络服务器。

This will make the job. You can put that either in a <Directory foo/> section or in a .htaccess file if you do not have access to apache configuration or if you want to slowdown your webserver.

这篇关于如何强制Apache在使用手动$ CSS和JS文件的对$ P-COM pressed GZ文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆