# Apache - precompressing static files with gzip

DevFeed: [Apache - precompressing static files with gzip](<https://devfeed.tech/articles/apache-precompressing-static-files-with-gzip-27596.md>)

Original publisher: [Read original article](<https://gagor.pro/2013/12/apache-precompressing-static-files-with-gzip/>)

Author: Tom

Published: 2013-12-27T00:00:00Z

Content type: tutorial

Language: en

Sources: [Tomasz Gągor](<https://devfeed.tech/sources/tomasz-gagor.md>)

Topics: [Compression](<https://devfeed.tech/topics/compression.md>), [configuration](<https://devfeed.tech/topics/configuration.md>), [CSS](<https://devfeed.tech/topics/css.md>), [Code](<https://devfeed.tech/topics/code.md>), [Web Development](<https://devfeed.tech/topics/web-development.md>)

Tags: [apache](<https://devfeed.tech/tags/apache.md>), [code](<https://devfeed.tech/tags/code.md>), [compression](<https://devfeed.tech/tags/compression.md>), [config](<https://devfeed.tech/tags/config.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [css](<https://devfeed.tech/tags/css.md>), [encoding](<https://devfeed.tech/tags/encoding.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [linux](<https://devfeed.tech/tags/linux.md>), [mod-rewrite](<https://devfeed.tech/tags/mod-rewrite.md>)

## AI overview

A tutorial on configuring Apache rewrite rules to serve precompressed CSS and JavaScript files when clients support gzip. It explains how to assign the correct content types and prevent mod_deflate from recompressing files, while warning against applying gzip encoding indiscriminately to all .gz files.

## Source excerpt

Some time ago I've show how to precompress js and css file with gzip to be available for Nginx's mod_gzip. In default configuration Apache don't have such module but similar functionality could be achieved with few custom rewirtes. Basically we will start with these rewrites to serve gzipped CSS/JS files if they exist and the client accepts gzip compression: RewriteEngine on RewriteCond %{HTTP:Accept-encoding} gzip RewriteCond %{REQUEST_FILENAME}\.gz -s RewriteRule ^(.*)\.(js|css)$ $1\.$2\.gz [QSA] Then we need to setup proper content types for such compressed files - I know how to do this in two ways: