You know how to turn compression on for one or more web pages with PHP, but what if you want to enable compression for your entire web site?
With an Apache Web Server, it’s very easy. All you do is identify the types of files you want to serve compressed, insert the list to your server configuration file, and reload your web server.
Typical types of files you would want to serve compressed every time include:
- Java Script
- Plain Text
You should also consider other “text” file types, like
.json files, for example, if you use or serve them extensively on your site.
You do not want your web server to compress files that are already compressed, such as popular media files and archive files. Typical media files like video, audio and image files are usually already compressed. In other words, if they exist with file extensions like
.mp3 etc., then they are already in some form of a compressed state.
Common (compressed) archive files include those that have
WordPress does not have a setting anywhere where you can enable compression for your web site. The instructions in this page is recommended, if you want your self-hosted WordPress-powered web site to run optimally.
Apache Web Server
If your web server is Apache, and if the mod_deflate module is enabled on it, the following method is the easiest way to get compression enabled for your entire web site. You just insert something like this to the
.htaccess file in your web document root folder:
About Apache module mod_deflate.
Or, if you want this to only apply to a particular directory (and its sub-directories), and you are able to add/modify httpd directives to a
<VirtualHost> container yourself – where the directory is