Using Apache Deflate: What do I do on the content end?

Hi,

I just uploaded a small HTML5 site to my server, that uses a bunch of CSS and js. Google webmaster tools is telling me to use Deflate to save 75% bandwidth. I get the concept and have seen a bunch of articles on configuring Apache (my host will do that part), but nothing explains what to do w/the content.

Do I Gzip and upload with something like WinRar or must it be done on the server via command line (yuck)? What else do I have to do or know for the content part? Is there a good tutorial anywhere for the content part?

Thanks guys.

It’s actually pretty straightforward, and only requires a couple of lines added to you .htaccess file.

Provided you (or your host) have mod_deflate enabled on the server, the following lines in your .htaccess file will compress any HTML, PHP, CSS or JS files:

<FilesMatch "\.(js|css|html|php)$">
SetOutputFilter DEFLATE
</FilesMatch>

(You don’t want to compress images, because most image formats are already compressed).

For more information, try searching for “mod_deflate tutorial”, or see https://httpd.apache.org/docs/2.4/mod/mod_deflate.html

Thanks TechnoBear.

So to be clear:

Once I have the support people configure Apache to run Deflate, all I have to do is add those 3 lines at the bottom of my .htaccess file and the server will know what to do?

Also, that means I can keep uploading updated js or CSS files as normal and not even think about updating anything else and the compression will happen automagically (upon serving content to a browser) for me?

Yes.

If you’re on shared hosting, you’ll probably find mod_deflate is already enabled; I’ve never had a shared host where it wasn’t.

Once you’ve added the lines to your file, you can check if it’s working by using REDbot (https://redbot.org/), or the Web Developer Toolbar will show you the information under “Document Size”.

[quote=“syakoban, post:3, topic:202104”]
Also, that means I can keep uploading updated js or CSS files as normal and not even think about updating anything else and the compression will happen automagically (upon serving content to a browser) for me?
[/quote]Yes. Any files with the extensions .css, .html, .js or .php will be compressed when served.

Thanks very much TechnoBear - working great!

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.