In this post, you will learn how to quickly add Expires and Cache-control headers to your WordPress Bitnami installation.
For the better website performance, you should enable Cache-control headers to cache static content, also it saves time to load times o visitors.
Checking existing headers
Before starting into this tutorial, you should check details in your website for existing Expires and Cache-control headers properly. To do this, run a test for your domain at GTMetrix.com.After running a performance report for my domain on GTMetrix.com, it was clear that my server did not have Cache-control headers installed, as the test responded with a failing grade.
You should read on way to configure Expires and Cache-control headers for your required website in case of, received an F grade for the Add expire headers suggestion.
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
- 3. Add expires headers
- 4. Restart Apache server
- 5. Test performance
1. Connect to your instance
From your Google Cloud dashboard, navigate to VM instances, and click the SSH button next to the virtual machine instance that is running your WordPress website.
If you are using AWS for instructions on how to SSH into your EC2 instance.
2. Enable expires module
After connecting to your virtual machine instance, run the command below to open your Apache server configuration file.
At the top right corner of the page, click on the keyboard icon, then select Ctrl+W to search.
After the search field opens, type expires then press Enter to search.
Eliminate the # symbol from next to the expires_module in order to activate it.
Lastly, enter CRTL + X, then Y, to save and exit the file.
3. Add expires headers
Enter the command below to open your Apache server application configuration file.
After opening your httpd-app.conf file, copy and paste the code below directly above the line that starts with . Lastly, enter CRTL + X, then Y, to save and exit the file.
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
Execute the command below to restart your Apache server.
5. Test performance
Now that you’ve configured Expires and Cache-control headers for your WordPress site, the next step is to justify that the changes were useful. Re-test your domain on GTMetrix.com to get an updated performance report, then navigate to the YSlow tab.
If you configured your Expires and Cache-control headers perfectly, you will receive a passing grade for the Add Expires Headers recommendation.
Frequently Asked Questions
Why do you need Expires and Cache-control headers?
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”.
What’s the way to check if both Expires and Cache-control headers are permitted?
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.
See More : >>>