How to Enable Browser Caching in Enhance Apache Using .htaccess
Browser caching helps your website load faster by storing static files (images, CSS, JavaScript) on the visitor’s device. When enabled correctly, returning visitors load your pages much faster and your server handles fewer requests.
This guide explains how to enable caching on an Enhance-managed Apache server using a simple .htaccess file.
Why Enable Caching?
- Faster page loads for returning visitors
- Reduced server load because fewer files are re-downloaded
- Better SEO as Google rewards optimized performance
- Improved user experience across all devices
Where to Place the .htaccess File
To apply caching, place the file here:
/public_html/.htaccess
If the file does not exist, create it.
Recommended .htaccess Configuration
The following rules enable compression, set caching for static files, and safely cache HTML for a short time.
1. Enable GZIP Compression
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>
2. Set Expiration Headers for Static Files
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresDefault "access plus 2 days"
</IfModule>
3. Cache HTML Safely (Short Duration)
A short cache is safest:
<FilesMatch "\.(html|htm)$">
FileETag None
<IfModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=3600, private, must-revalidate"
</IfModule>
</FilesMatch>
How to Apply This in Enhance
- Log into your Enhance panel.
- Open Websites→ File Manager.
- Navigate to public_html/.
- Create or edit the
.htaccessfile. - Paste the full configuration above.
- Save the file.
How to Verify Caching Is Working
You can test caching using your browser’s developer tools:
- Open Chrome DevTools → Network tab.
- Reload the page.
- Click any CSS, JS, or image file.
- Check the Response Headers section.
You should see:
- Cache-Control with long durations for static files
- Expires header
- Content-Encoding: gzip for compression
Important Notes
- If you update CSS or images, add a version number (e.g.,
app.css?v=2) so browsers fetch the new file. - If you make a mistake in
.htaccess, Apache may show a 500 error. Simply remove or correct the file.
Conclusion
By enabling caching through .htaccess, your website becomes significantly faster and more efficient. This improves user experience, reduces server load, and enhances SEO performance.