Add Expires Headers for WordPress on Google Cloud (Bitnami)
Adding Expires and Cache-control headers is a great way to improve user experience by reducing your website’s load time.
In this tutorial you will learn how to quickly add Expires and Cache-control headers to your WordPress Bitnami installation.
Configuring Expires and Cache-control headers enables your website to cache static content, leading to better website performance and reduced load times for visitors.
Checking existing headers
Before diving into this tutorial, you should check your website for existing Expires and Cache-control headers. To do this, run a test for your domain at GTMetrix.com.
If you received an F grade for the Add Expires Headers recommendation, then read on to learn how to configure Expires and Cache-control headers for your website.
Before getting started with this tutorial, you should have already installed the Bitnami WordPress (LAMP) stack on Google Cloud. If you haven’t yet done this, check out the following tutorials for instructions on how to install the Bitnami WordPress stack on Google Cloud.
There are 5 steps in this tutorial:
1. Connect to your instance
2. Enable expires module
sudo nano /opt/bitnami/apache2/conf/httpd.conf
3. Add expires headers
sudo nano /opt/bitnami/apps/wordpress/conf/httpd-app.conf
Header set Cache-Control "max-age=2592000, public"
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
4. Restart Apache server
sudo /opt/bitnami/ctlscript.sh restart
5. Test performance
Now that you’ve configure Expires and Cache-control headers for your WordPress website, the next step is to test that the changes were effective. Re-test your domain on GTMetrix.com to get an updated performance report, then navigate to the YSlow tab.
Frequently Asked Questions
- Why do you need Expires and Cache-control headers?
- How do you check if both Expires and Cache-control headers are enabled?
According to Kartik Ayyar, Machine Learning engineer at Google, you should “use both, primarily because different browsers and intermediate proxies can implement parsing these headers slightly differently and you want to insulate yourself from bugs in either”.
You can view your Expires and Cache control settings by running a performance report for your website on GTMetrix.com, then clicking on one of your website’s images under the Waterfall tab.
If you have any questions or comments regarding this tutorial, please leave them in the comment field below.
For troubleshooting support, be sure to check out the WordPress Cloud Hosting Support Group on Facebook.