enable browser caching

How to Enable Browser Caching?

Enabling browser caching typically involves configuring your web server. Here are some common methods:
Apache: Add caching rules in the .htaccess file. Example:
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
NGINX: Add caching rules in the server block. Example:
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
CDNs: Content Delivery Networks like Cloudflare and Akamai offer easy ways to implement caching at the edge server level.

Frequently asked queries:

Relevant Topics