Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to set up browser caching with mod_expires

This guide shows you how to use the Apache mod_expires module to make your website load faster for returning visitors.

How-To Guides2 min read12 steps

What is mod_expires?

Caching means a browser keeps a saved copy of a file, such as a picture. The next visit is faster because the browser does not download it again.

mod_expires is a part of the Apache web server. It adds a note to each file that says how long the browser may keep it. It is like a "use by" date on food.

Before you start

  • Your site must run on Apache. Ask Hostvento support if you are unsure.
  • mod_expires must be turned on. On most hosting it is.
  • You will edit a file called .htaccess. It is a settings file in your site folder. Dot files are hidden, so turn on "show hidden files" in your File Manager.

Warning: a mistake in .htaccess can break your site. Download a backup copy first.

Steps

  1. Log in to your hosting control panel.
  2. Open File Manager and go to your website folder, often public_html.
  3. Find .htaccess. If it does not exist, create it.
  4. Download a copy as a backup.
  5. Open the file for editing.
  6. Add the block below at the end of the file.
  7. Save the file.
  8. Reload your site and check it works.
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
  ExpiresByType text/html "access plus 0 seconds"
</IfModule>

These lines turn on expiry and set a time for each file type. The IfModule wrapper keeps your site safe if the module is missing.

Choosing times

  • Pictures and fonts rarely change. A long time such as one year is fine.
  • CSS and JavaScript change more often. One month is a safe choice.
  • Web pages should have a very short time or none.

Check that it works

  1. Open your site in a browser.
  2. Press F12 to open developer tools and click the Network tab.
  3. Reload the page and click an image.
  4. Look for an Expires or Cache-Control header in the details.

You can also run a speed test tool like GTmetrix. It warns you when caching is missing.

Tip: If you change a cached file, visitors may still see the old one. Rename the file or add a version number, such as style.css?v=2.

Quick recap

  • mod_expires tells browsers how long to keep files.
  • Add rules to .htaccess after taking a backup.
  • Use long times for images and short times for pages.
  • Check the headers in your browser tools.