Skip to content

Instantly share code, notes, and snippets.

@SitesByYogi
Created August 23, 2024 13:16
Show Gist options
  • Save SitesByYogi/26c14a974798717451f89c9d2713398d to your computer and use it in GitHub Desktop.
Save SitesByYogi/26c14a974798717451f89c9d2713398d to your computer and use it in GitHub Desktop.
If your WordPress site is hosted on an Apache server, you can use the .htaccess file to add expiration headers and control the cache policy. Here’s an example of how you might configure it:
<IfModule mod_expires.c>
ExpiresActive On
# Set default expiration to 1 month
ExpiresDefault "access plus 1 month"
# Specific expiration times by file type
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 text/css "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType application/x-javascript "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType application/font-woff2 "access plus 1 year"
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment