Cache static content using htaccess
Question:
How to cache static content using htaccess? Answer:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 12 month"
ExpiresByType image/jpeg "access 12 month"
ExpiresByType image/gif "access 12 month"
ExpiresByType image/png "access 12 month"
ExpiresByType image/webp "access 12 month"
ExpiresByType text/css "access 12 month"
ExpiresByType text/x-javascript "access 12 month"
ExpiresDefault "access 30 days"
</IfModule>
Description:
The mod_expires
module controls the setting of the Expires
HTTP header and the max-age
directive of the Cache-Control
HTTP header in server responses. The expiration date can set to be relative to either the time the source file was last modified or to the time of the client access.
These HTTP headers are an instruction to the client about the document's validity and persistence. If cached, the document may be fetched from the cache rather than from the source until this time has passed. After that, the cache copy is considered "expired" and invalid, and a new copy must be obtained from the source.
Reference:
The mod_expires module reference
Share "How to cache static content using htaccess?"
Related snippets:
- Change default terminal in VS Code
- Change colors in VS Code integrated terminal
- Change file encoding in VS Code
- Setup HTTPS for local development on Windows 10
- Add cookie in Chrome
- Setup xdebug 3 debugger for PHP
- Set default encoding to UTF-8 using Apache
- Enable compression in Apache using htaccess
- Cache static content using htaccess
- Redirect all requests to index.php using htaccess
- Set X-Frame-Options on Apache webservers
- Redirect www to non-www on Apache webservers
- Automatically redirect HTTP to HTTPS on Apache webservers
- Set X-Content-Type-Options in Apache
Tags:
cache static content, modify expires header, apache, htaccess Technical term:
Cache static content using htaccess