Speedup WordPress (Nginx’s Gzip_static + Minify + W3 Total Cache)

There’s several ways to speedup WordPress:-

iNotifyMinifyGzip.sh - Caching Files
iNotifyMinifyGzip.sh – Caching Files
  • Gzip or Deflate compression.
  • Minify HTML, CSS and JS files.
  • Browser’s Cache-Control.
  • Front-end proxy/page cache.

Disclaimer: As I’m frequently updating the original guides and installers here on TeaNazaR.com, I will not be responsible for any brick issues if you were to follow my obsolete guides copied elsewhere. Thus subscribe to this post to get latest updates. Modifying any part of a device may void its warranty.

Most notably with WordPress’s W3 Total Cache plugin which have the ability to perform all four methods above. While this a plus point of having all-in-one, I have to take into consideration for the system resources. Trying to perform all these at once in a single PHP request apparently bogs down my tiny WDMyCloud 4TB NAS which only has 650MHz dual core and 256Mb ram.

So I decided to split the process. W3 Total Cache plugin will only perform the page caching production. Then introduce an external monitoring shell script to gzip and minify (htm/html/scss/css/js) the cached page when there’s changes on a lower priority run. Nginx on the other hand will handle the serving of GZIP cached contents. The advantage to this is that I can also automatically gzip all other necessary contents (e.g. jpg, png etc.) almost on-the-fly without impacting the main PHP process.

The setup are accomplished as follows:-

  1. Only let WordPress’s W3 Total Cache plugin cache the accessed pages (no gzip or minify), the rest are possibly left as default or your preferences: In the ‘Performance -> General Settings’, only enable below:
    a) Enabled ‘Page cache’. ‘Page cache method’ set to ‘Disk Enhanced’. Go to the ‘Page Cache’ page and enable ‘Cache posts page/feeds/SSL’. It’s also recommended to prime and preload the cache if you have any sitemap plugin already installed. I did my cache priming with the external ‘wp-cron.php’ cronjob script as described in my other post here.
    b) Enabled ‘Browser Cache’. Go to the ‘Browser Cache’ page enable all four ‘Set expires header’ and disable all four ‘Enable HTTP (gzip) compression’.


  2. Place the script below somewhere on your server, make the script executable chmod 0755 ./iNotifyMinifyGzip.sh (assuming the script is in the current path) and schedule a cronjob  crontab -e  to run it at boot as a HTTPD user i.e. “www-data” (WP plugins will have permission issues upgrading if caches created as root), then add the schedule to a new line:

    You can change the nice priority accordingly, nice -n19 as the lowest and nice -n-20 as the highest (not recommended) or just omit the nice command to run at normal priority. For testing purposes, you can run it normally on the terminal ./iNotifyMinifyGzip.sh (assuming the script is in the current path). To run the process permanently in background, use  sudo -u www-data nohup ./iNotifyMinifyGzip.sh >/dev/null 2>&1 &. If you’ve made changes to the script, just re-run it again and the previous process will get terminated. To stop it, issue killall iNotifyMinifyGzip.sh inotifywait.


  3. Prepare the requirements and follow instructions in the script below to activate the auto monitoring:

iNotifyMinifyGzip.sh

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax