- Instant help with your Developer coding problems

Cache static content using htaccess

How to cache static content using htaccess?
<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"

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.

Share "How to cache static content using htaccess?"