Tag Archives: Mod_Expires

How To Enable mod_expires With WordPress Plugins For A Better Site Performance?

If you’re using WordPress, you can enable mod_expires and set up caching rules easily using plugins. This method doesn’t require manual server configuration and can help you boost your website’s speed.

Several WordPress plugins can enable mod_expires and set up caching rules. Popular options include: WP Super Cache, W3 Total Cache, WP Rocket, and Hummingbird. For this lesson, let’s focus on W3 Total Cache and WP Super Cache, as they are free and commonly used.

To enable mod_expires through WordPress plugins, you can set up caching rules without manually configuring the server. This helps to improve your website’s loading speed and overall performance. Here’s how to do it using popular caching plugins for WordPress.

Step 1 Installing W3 Total Cache Plugin

Start by installing and activating the W3 Total Cache plugin. Navigate to the WordPress Dashboard, go to Plugins, then Add New, and search for W3 Total Cache.

Step 2 Enabling mod_expires With W3 Total Cache

After activation, go to Performance > Browser Cache in the WordPress dashboard. There, you will find an option to enable the “HTTP (Expires) Header” for different content types, such as CSS, JavaScript, and HTML.

Make sure to check the box for each relevant type and configure the expiration settings.

For example, you could set the “Expires header lifetime” to one week for CSS and JavaScript, while setting it to one month for images. Don’t forget to save your settings and purge the cache afterward.

Step 1 Installing WP Super Cache Plugin

Start by installing and activating the WP Super Cache plugin. Navigate to the WordPress Dashboard, go to Plugins, then Add New, and search for WP Super Cache.

Step 2 Enabling mod_expires Using WP Super Cache

Activate the WP Super Cache plugin. Next, go to the WordPress Dashboard, select Plugins, and then Add New. Search for WP Super Cache, install it, and activate the plugin.

Now, head over to Settings > WP Super Cache > Advanced. In this section, you will find an “Expiry Time & Garbage Collection” area.

Enable the “Cache HTTP headers with expires” option, and set an appropriate expiration time for your content.

For instance, 3600 seconds (1 hour) may work for dynamic content, whereas static files like images could have a longer expiration period. Once you’ve made these adjustments, update the status.

Step 3 Verify That Cache Is Working (Common Step)

Clear your site cache through the plugin’s settings to apply all changes. You can then check the HTTP headers using the developer tools in your browser or online services like GTmetrix. This will help confirm that the “Expires” or “Cache-Control” headers are correctly set.

By following these steps, you can easily enable mod_expires through plugins like W3 Total Cache and WP Super Cache, optimizing caching rules for better website performance without directly modifying server configurations.

How To Enable mod_expires To Cache Your Website Files For Speed?

Mod_Expires is a built-in module for the Apache web server, available on all Sangkrit.net hosting plans. This module leverages the functionality of mod_expires to manage how long a client’s web browser caches website resources.

Here’s how it works: Mod_Expires manipulates the “Expires” headers sent by the hosting server. This gives you control over how long a browser stores cached copies of website resources. By adjusting these cache durations, you can optimize your site’s performance while considering your website’s update frequency.

Important Note: If the server response already includes an “Expires” header (e.g., generated by a CGI script or a proxied origin server), Mod_Expires won’t modify or add an “Expires” or “Cache-Control” header in those cases.

How To Enable mod_expires Via .htaccess?

If Mod_Expires is not enabled you will need to enable it in your .htaccess file which is present in your website’s root directory, sometimes hidden and can be viewed by changing the view option from the top right corner of cPanel’s file manager. You can enable it on a per-directory basis and it applies recursively.

Sangkrit.net uses the vendor-provided code from Apache mod_expires. Apache HTTPD documentation is accurate for using .htaccess files on your hosting account.

Locate your .htaccess file: This file is usually located in your website’s root directory (e.g., /var/www/html/). The following given example enables mod_expires for a set of common image types and CSS files:

# Activate mod_expires for this directory
ExpiresActive on
# locally cache common image types for 7 days
ExpiresByType image/jpg "access plus 7 days"
ExpiresByType image/jpeg "access plus 7 days"
ExpiresByType image/gif "access plus 7 days"
ExpiresByType image/png "access plus 7 days"
# cache CSS files for 24 hours
ExpiresByType text/css "access plus 24 hours"

Similarly, you can configure mod_expires in your .htaccess file with more options by adding extra caching rules.

Open the .htaccess file and add the following code to specify the caching duration for different file types:

<IfModule mod_expires.c>
    ExpiresActive On
    # Set expiration for images
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    # Set expiration for CSS and JavaScript
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
    ExpiresByType text/javascript "access plus 1 week"
    # Set expiration for other file types
    ExpiresByType text/html "access plus 1 day"
    ExpiresByType application/pdf "access plus 1 month"
    ExpiresDefault "access plus 1 week"
</IfModule>

How To Enable mod_expires Via Apache Server?

Alternatively, if you have root or administrative access to your server you can enable mod_expires directly in Apache by using the command line. Simply, access your server and do as directed.

Step-1 Enable the module by running the following command:

bash
sudo a2enmod expires

Step-2 After enabling the module, restart Apache to apply the changes. Simply use the following command for restarting apache :

bash
sudo service apache2 restart

Now clear your browser cache to ensure you see the latest changes.

You may also check HTTP headers by using browser developer tools (Network tab) to confirm that the “Expires” or “Cache-Control” headers are set correctly for the specified file types.

By enabling mod_expires, you can significantly reduce page load times, as browsers will cache static files and serve them locally on subsequent visits.

How To Enable Mod_Expires Via WordPress Plugins?

WordPress users may also use some cache plugins such as WP Super Cache or W3 Total Cache to get this thing done from their admin area dashboard. Read this lesson to know the complete process.