> ## Documentation Index
> Fetch the complete documentation index at: https://kb.hosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Configuring caching with the mod_expires module

> Configure caching with mod_expires using this guide's code snippets and instructions to set web content expiration.

This article is an introduction to Apache's document expiration functionality provided by the **mod\_expires** module.

Setting expiration periods for web content enables web browsers to cache content for specific periods of time. As a result, you can reduce the number of HTTP requests that the web server must process, which helps improves web site speed and performance.

## Using the mod\_expires module

Apache's **mod\_expires** module enables you to define expiration intervals for different types of content on your web site. For example, you could use **mod\_expires** directives to instruct browsers to cache image files for one hour, JavaScript files for two weeks, and CSS files for two months.

The following sample *.htaccess* configuration demonstrates how to do this:

```
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/png "access 1 hour"
    ExpiresByType image/gif "access 1 hour"
    ExpiresByType image/jpeg "access 1 hour"
    ExpiresByType text/javascript "access 2 weeks"
    ExpiresByType text/css "access 2 months"
    ExpiresByType text/html "modification 4 hours"
    ExpiresDefault "access 2 days"
</IfModule>
```

In this example:

* The **ExpiresActive** directive is set to **On**, which instructs Apache to generate **Expires** and **Cache-Control** HTTP response headers for the specified content types. Web browsers parse these HTTP response headers to determine how long to cache content on the client.

* The **ExpiresByType** directives define the expiration periods for specific types of content. You can specify expiration periods in seconds, minutes, hours, days, weeks, months, and years. To define a specific type of content, use the MIME type, such as *text/html* or *image/png*. For a list of MIME types, please visit [https://en.wikipedia.org/wiki/Internet\_media\_type](https://en.wikipedia.org/wiki/Internet_media_type).
  > 📘 Note
  >
  > There are actually two ways to define expiration periods. You can specify an expiration period from the time the browser accesses the file by using the **access** keyword. Alternatively, you can specify an expiration period from the time the file was last modified on the server by using the **modification** keyword.

* The **ExpiresDefault** directive is an optional directive that specifies the expiration period for all other types of files not explicitly set in an **ExpiresByType** directive. In this example, any file that is *not* an image, JavaScript, or CSS file expires in two days.

<Tip>
  To verify your expiration settings in the *.htaccess* file are working correctly, you can examine the raw HTTP headers sent between the browser and web server. (To do this, use a browser plugin that displays the raw headers such as Live HTTP headers for Mozilla Firefox, or the Developer Tools feature in Google Chrome.) When content is marked for expiration, Apache adds the following lines to the HTTP response header (the exact values will vary based on your own*.htaccess* settings):

  ```
  Cache-Control: max-age=86400
  Expires: Thu, 02 Oct 2014 19:02:30 GMT
  ```
</Tip>

## More information

For more information about the **mod\_expires** module, please visit [https://httpd.apache.org/docs/2.2/mod/mod\_expires.html](https://httpd.apache.org/docs/2.2/mod/mod_expires.html).

## Related articles

* [Using .htaccess files](/docs/using-htaccess-files)
