Enable Apache’s mod_deflate module, then apply its DEFLATE output filter to the text responses you want compressed. For most sites, the safest starting rule is AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript in the appropriate server, virtual-host, directory, or permitted .htaccess context. Apache negotiates gzip with browsers; the module does not provide the deflate content-encoding used by some other systems.
Need a server to try this on? Antihost offers Linux VPS plans with NVMe storage, full root access and a 14-day free trial.
What mod_deflate does
Apache’s mod_deflate is a response-compression module. It supplies the DEFLATE output filter, which compresses a response on the server before Apache sends it across the network. The client receives the compressed representation and decompresses it before rendering the page or executing the file. This can reduce bytes transferred for text-heavy responses such as HTML, CSS, JavaScript, XML, and plain text.
As an Amazon Associate I earn from qualifying purchases.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesThe module works at the output stage. It does not rewrite your source files, replace your JavaScript, or permanently create compressed copies on disk. Apache decides whether to apply the filter while generating each response, based on the rules in the configuration and the client’s advertised encodings.
“The
mod_deflatemodule provides theDEFLATEoutput filter that allows output from your server to be compressed before it is sent to the client over the network.” — Apache HTTP Server 2.4 documentation#1 Best Overall
Compression is normally useful for textual content because repeated words, tags, property names, and punctuation can be represented more efficiently. GIF, JPEG, and PNG files are already compressed formats; running a general-purpose text compressor over them usually adds CPU work without reducing the payload. The MIME rules and exclusions below keep the filter focused on suitable responses.
Choose the right configuration pattern
Apache documents two practical ways to attach the filter. Pick one deliberately rather than enabling both for the same container.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →| Pattern | Example | Best use | Main trade-off |
|---|---|---|---|
| Broad filter | SetOutputFilter DEFLATE |
A controlled container where every generated response is known to be appropriate for compression. | It can affect binary or already-compressed responses unless you add exclusions and test every response type. |
| MIME-scoped filter | AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript |
General websites that want to compress selected text responses while leaving unrelated types alone. | Only responses whose final MIME type matches the list are covered; missing or incorrect MIME mappings will prevent compression. |
For a typical site, MIME scoping is the safer default. The broad form is concise, but its scope is determined by the container in which it appears. A rule in a wide server or virtual-host context can reach more responses than you intended.
Confirm that the module and configuration can be changed
Identify the Apache deployment
You need administrative access to the Apache configuration, or permission to use an allowed .htaccess file. A hosting account that permits file uploads but disallows override directives cannot enable this feature from the document root alone. Ask the administrator to enable the module or change the virtual-host configuration in that case.
Configuration locations differ by distribution and installation method. The directive can be placed in the main server configuration, a virtual-host block, a <Directory> container, or an .htaccess file when the server’s override policy permits it. The correct location is the one that governs the responses you want to compress.
Check whether mod_deflate is loaded
On systems that provide module-management helpers, enable the module with the platform’s normal Apache command (for example, Debian-based installations commonly use a2enmod deflate) and reload or restart Apache afterward. Other installations load modules from their main configuration and may already include mod_deflate; do not add a second LoadModule line blindly.
Free tools Windows power users keep installed
One-click scans. No signup required.
Use your installation’s Apache module listing to confirm that deflate_module is present. A syntax check should be run before a reload. If the check reports an unknown directive or a missing module, fix that first; an invalid configuration can prevent Apache from reloading and leave the previous configuration running.
Enable compression with MIME-type scoping
Add the following rule to the applicable configuration container:
Rank #2
- Used Book in Good Condition
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
This asks Apache to apply the DEFLATE output filter when the response’s MIME type is one of the listed values. The example covers HTML, plain text, XML, CSS, the traditional JavaScript type, and the common application/javascript type. Add other textual types only when you know the application emits them and has assigned the correct Content-Type.
A directory-scoped configuration can be written as a container when you administer the server configuration:
<Directory "/var/www/html">
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
</Directory>
Replace the directory with the real path used by your virtual host. In a virtual-host block, the same directive affects that host’s responses. In .htaccess, omit the surrounding container and put the directive directly in the file:
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
The .htaccess version works only if the server allows the relevant override class. If Apache returns a 500 error after you add it, inspect the error log and remove the directive until the administrator confirms the permitted context.
Use broad filtering only in a controlled container
The alternative documented pattern is:
SetOutputFilter DEFLATE
This enables the filter broadly for the container where it appears. It is appropriate only when you have inventoried the responses in that scope and are comfortable handling unsuitable content separately. A broad rule can catch downloads, images, archives, or application responses that should not be compressed with a text-oriented filter.
If you start broad, test every important route and add exclusions before production traffic reaches the server. For most public sites, the MIME-scoped rule communicates intent more clearly and reduces the number of accidental matches.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Exclude formats that are already compressed
Apache’s example uses an environment flag to skip common pre-compressed images:
SetEnvIfNoCase Request_URI ".(?:gif|jpe?g|png)$" no-gzip
Place the exclusion where it is evaluated for the same requests as your filter rule. The regular expression matches GIF, JPEG, JPG, and PNG filename endings without regard to case, then marks those requests with no-gzip. This is particularly important when a broad SetOutputFilter DEFLATE rule is in use.
Do not assume that a filename extension always tells you the response type. Dynamic endpoints can return different content for the same path, and a download may be generated without an image extension. Verify the actual Content-Type and response behavior when deciding whether an exclusion is necessary.
How browser negotiation works
Compression must be negotiated. A browser sends an Accept-Encoding request header describing encodings it can decode. Apache can then return a compressed representation using the supported gzip content encoding when the response is eligible for the filter.
Recommended Free Tools
Apache’s documentation treats gzip as the browser-compatible content encoding for this module. The module does not support the deflate encoding name. Do not configure a rule that assumes the two names are interchangeable: DEFLATE is the name of Apache’s output filter, while gzip is the encoding used for ordinary browser responses.
Clients that do not advertise a supported encoding should receive an uncompressed response. That fallback is part of correct negotiation, not a failure. API clients, health checks, command-line tools, and older software may make different header choices from a modern browser.
Keep cache and proxy metadata correct
Compressed and uncompressed representations of the same URL vary according to the request’s Accept-Encoding value. Apache and any intermediary cache must preserve that variation. The response should therefore carry an appropriate Vary: Accept-Encoding header so a cache does not serve a compressed representation to a client that cannot decode it, or unnecessarily reuse an uncompressed representation for a client that requested gzip.
Direct-origin deployment is simpler because Apache negotiates with the end client. A reverse proxy, CDN, or shared cache introduces another negotiation boundary. Decide whether Apache compresses before the intermediary, whether the intermediary compresses after receiving an uncompressed response, or whether both layers might attempt to do so. Ensure that only one layer is responsible for each representation and that cache keys and Vary handling match that design.
| Deployment | What to verify |
|---|---|
| Apache serves clients directly | The client sends Accept-Encoding, Apache returns the negotiated encoding, and the response advertises the variation. |
| Apache behind a reverse proxy | The proxy forwards or intentionally terminates encoding negotiation, preserves the variation metadata, and does not double-compress. |
| Apache behind a cache | Cache entries distinguish requests with different encoding support, and purges or revalidation cover both representations. |
Security: do not compress secrets indiscriminately
Compression can create an information-disclosure risk when encrypted traffic contains both a secret and attacker-influenced text. Apache warns that some web applications are vulnerable when TLS carries deflate-compressed data, a class of issues associated with BREACH-family attacks.
The risk is application-specific. Review responses that contain anti-forgery tokens, password-reset values, session-related secrets, or other confidential data alongside values an attacker can influence. For sensitive endpoints, possible mitigations include disabling compression for that response, separating secrets from reflected input, reducing secret exposure, and following the application framework’s guidance. Do not enable compression globally and assume TLS alone removes the risk.
Rank #4
Compression of public, static text is usually a different risk profile from compression of personalized pages containing secrets. Make the decision per response class, not solely per file extension.
Test the result from the command line
Test a URL that is known to return one of your selected MIME types. Send an explicit encoding header, inspect the response headers, and save the body if you need to examine it:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
curl -I -H 'Accept-Encoding: gzip' https://example.test/
For a complete response, use a command that requests gzip and allows the client to decompress it for display:
curl --compressed -i https://example.test/
Look for a gzip content encoding on an eligible response, a matching Content-Type, and a Vary value that includes Accept-Encoding. Then repeat the request without the header or with a client that does not advertise gzip; it should receive a valid uncompressed response.
Test more than the home page. Include a CSS file, JavaScript file, an XML or plain-text endpoint if your application serves one, an image, a download, and a personalized page. Compare the headers and confirm that the filter has not altered content, broken range or download behavior, or compressed data that should remain untouched.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshoot common failures
The directive is reported as unknown
Apache is probably not loading mod_filter or mod_deflate, or the directive is being read in a context where its module is unavailable. Check the loaded-module list and the configuration syntax output. Enable the module using the distribution’s supported method, then reload Apache.
The site returns HTTP 500 after editing .htaccess
The server may disallow that directive in .htaccess. Read the Apache error log, remove the new rule to restore service, and move the configuration into the virtual-host or directory configuration, where an administrator can grant the correct override policy.
No compression header appears
- Confirm that the request actually advertises gzip or another encoding Apache can negotiate.
- Check the response’s final
Content-Typeagainst every MIME value inAddOutputFilterByType. - Check that the response is not marked with
no-gzipby an exclusion rule. - Verify that another module, application layer, or reverse proxy has not replaced the response or removed the relevant headers.
- Make sure you reloaded the configuration you edited and are testing the intended virtual host.
Images or archives become slower
Remove them from a broad filter scope or add exclusions. GIF, JPEG, and PNG are the formats Apache’s sample specifically avoids. Extend the same reasoning to other formats that are already compressed, and measure CPU and transfer behavior before applying a blanket rule.
Best Value
- Used Book in Good Condition
A cache serves the wrong representation
Inspect the response’s Vary metadata and the intermediary’s cache-key policy. A cache that ignores Accept-Encoding can mix compressed and uncompressed variants. Correct the proxy or cache configuration before relying on compression in production.
Do not confuse response compression with input decompression
The module’s ordinary use is output compression: Apache compresses responses it is sending. Apache documentation also describes input decompression and output inflation for specialized proxy or WebDAV scenarios. Those features address different traffic flows and should not be enabled casually as part of a normal browser-compression setup.
If an application needs clients to upload compressed request bodies, treat that as a separate design and security review. It has different resource limits, trust assumptions, and failure modes from compressing HTML or JavaScript on the way out.
Set expectations for speed and size
There is no universal compression ratio for mod_deflate. Results depend on the content, its existing compression, the selected MIME types, response size, and the server and client path. Repetitive HTML, CSS, JavaScript, XML, and plain text generally offer more opportunity than binary media, but the exact reduction must be measured on your own responses.
Compression trades server CPU time for fewer network bytes. A rule that helps a large text response over a slow connection may provide little benefit for a tiny response or a fast local client. Monitor server load, response latency, transfer size, and error rates after enabling it. Keep exclusions for formats where the extra CPU work does not produce a useful smaller representation.
Production checklist
- Confirm that the Apache installation loads
mod_deflate. - Choose a container whose scope matches the responses you intend to affect.
- Prefer
AddOutputFilterByTypefor a normal site unless you have a reason to use broad filtering. - List the actual text MIME types your application returns, including both common JavaScript types when needed.
- Exclude GIF, JPEG, PNG, and other already-compressed formats when a broad rule could reach them.
- Validate syntax before reloading Apache.
- Test with and without
Accept-Encoding: gzip. - Check content type, content encoding, and
Vary: Accept-Encodingon direct responses. - Test through every reverse proxy or cache in the production path.
- Review personalized and TLS-protected responses for BREACH-family information-disclosure exposure.
- Monitor CPU, latency, transfer size, cache behavior, and application errors after rollout.
A compact configuration example
The following example combines MIME scoping with Apache’s documented image exclusion. Adapt the paths and container to your deployment rather than pasting it into an arbitrary location:
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11<Directory "/var/www/html">
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
SetEnvIfNoCase Request_URI ".(?:gif|jpe?g|png)$" no-gzip
</Directory>
After placing the rule, run the server’s configuration test, reload Apache, and verify representative responses from the public URL. If your hosting environment does not permit a <Directory> block, use the equivalent virtual-host or approved .htaccess form. The correct result is negotiated gzip for eligible text responses, a valid uncompressed fallback for clients that do not support it, and no accidental compression of excluded media.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




