Set up browser caching with .htaccess to tell browsers how long they may reuse static files such as images, stylesheets and JavaScript. On Apache, mod_expires can generate the Expires and Cache-Control: max-age response headers for selected content types.
We recommend starting with static assets, not a site-wide rule for every response. Below, we replace broad caching examples with a scoped configuration, explain when longer lifetimes are appropriate, and show what to check after saving.
What these rules do and do not cache
A browser cache holds previously downloaded responses on a visitor's device. While a response is fresh, the browser may reuse it rather than download it again. A CDN or server-side page cache is a separate layer; setting browser headers is not the same as installing a page cache or configuring every CDN setting.
Our explanation of web caching covers those distinctions. For CDN-specific behavior, see Cloudflare cache. Here, the goal is narrower: make your origin server send an intentional freshness policy for public static resources.
For example, we might allow an unchanged logo to be reused while requiring an account page to be checked again. Those resources need different policies. Do not assume that one expiration time is safe simply because it improves a performance report.
Need the domain first?
Runs the same live check as the front page. If it is taken we will show you when it expires.
Step 1: check Apache support and make a backup
These directives require Apache with mod_expires available and permission to use its directives in the relevant directory. ExpiresActive needs the Indexes override category, or equivalent permission through the server configuration. Your hosting provider controls those permissions.
Download a backup of the existing file before editing. Use your host's file-access method to find the document root for the particular site. It may be called public_html, but do not assume that directory is correct for every domain. Enable hidden-file visibility if needed, because the filename begins with a dot.
If there is already a file, edit it instead of replacing it. Keep unrelated redirects, access restrictions and application rules intact. Our .htaccess guide explains the file's directory scope. Administrators who can edit Apache's main configuration should generally use that configuration instead.

Step 2: add a scoped static-file policy
The following is an example starting policy, not a universal recommendation. We use a week for the listed image and document types and a day for CSS and JavaScript. Choose shorter periods if the same URLs change frequently and you cannot version them.
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpeg "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/webp "access plus 1 week"
ExpiresByType image/svg+xml "access plus 1 week"
ExpiresByType text/css "access plus 1 day"
ExpiresByType text/javascript "access plus 1 day"
ExpiresByType application/javascript "access plus 1 day"
ExpiresByType application/pdf "access plus 1 week"
</IfModule>ExpiresActive On turns on header generation; it does not install or load a missing Apache module. The surrounding IfModule condition skips the block when that module is unavailable. Consequently, a site that still loads normally is not proof that the caching policy took effect.
ExpiresByType matches the response's media type, not just the filename extension. Include the JavaScript type your server actually returns. Avoid copying a misspelled type or a directive with missing whitespace: the browser receives headers for the response served, not the filename you intended.
Step 3: choose longer expiry only with an update plan
When assets have versioned URLs, we can give them longer freshness periods without trapping visitors on an older file at the same address. For example, a deployment can reference app.v2.css instead of app.v1.css. A content hash in the filename is another versioning approach.
To adapt the example, change an individual interval to something like "access plus 1 year" only when that resource's URL changes whenever its content changes. This is a policy choice, not evidence that every image should remain cached for a year.
Changing a server header later does not reliably recall copies that browsers already consider fresh. Keep an update strategy before choosing long lifetimes. Purging a managed CDN cache is a different operation from removing cached files on visitors' devices.
Step 4: leave dynamic HTML to its own policy
We deliberately omit ExpiresDefault and text/html from the example. A broad default or long HTML lifetime can affect content that should change immediately. Review login, cart, checkout and personalized responses separately with the application or hosting provider.
The relevant Cache-Control terms have different meanings: no-cache allows storage but requires validation before reuse; no-store tells caches not to store the response; private prevents shared caches from storing a personalized response. They are not interchangeable labels for turning caching off.
Do not add all of them indiscriminately to every file. Establish which layer owns dynamic-response headers, then check that its policy does not conflict with static-asset settings. For a broader performance change, our GZIP compression guide covers a separate technique rather than a replacement for caching.
Step 5: save and verify the actual response
- Save the edited file in the intended site directory.
- Open an actual image or stylesheet URL and inspect its response headers in the browser's network tools.
- Check the Content-Type, Cache-Control and Expires values rather than assuming the block applied.
- Test the homepage and important application routes for errors.
- If the change breaks requests, restore the backup and inspect the server error log with your host.
If a proxy or CDN sits in front of Apache, compare its delivered headers with the origin policy. Apache also notes that mod_expires does not replace Expires or Cache-Control when an Expires header already comes from the response-generating source. Missing or unexpected headers therefore need investigation, not more duplicate rules.
Common questions
Does this guarantee a faster site or better rankings?
No. These rules define cache behavior for eligible responses. Verify their effect on your own assets; they do not fix every performance problem or guarantee search results.
Can this help when launching a new domain?
It can be part of the hosting setup, but first choose the name and establish the site. Our domain name generator is for exploring naming ideas, not checking HTTP cache behavior.