Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set cache expiration?

Tags:

html

caching

I tested my site with Chrome and got the following recommendation:

The following resources are missing a cache expiration. Resources that do not specify an expiration may not be cached by browsers: style.css jquery.marquee.js jquery.marquee.css logo.png 

How do I set the cache expiration for these files?

like image 705
lisovaccaro Avatar asked Aug 20 '11 20:08

lisovaccaro


People also ask

How do I set the expiry for cache?

One of the way to Set cache expiration is by using . htaccess file. Below code will set expiration for it's respective file type, e.g. for CSS files expiration will be 14 days.

What is cache expire time?

By default, each file automatically expires after 24 hours, but you can change the default behavior in two ways: To change the cache duration for all files that match the same path pattern, you can change the CloudFront settings for Minimum TTL, Maximum TTL, and Default TTL for a cache behavior.

How do I change my Cache-Control max age?

Cache-Control: max-age=<seconds> This directive tells the browser or intermediary cache how long the response can be used from the time it was requested. A max-age of 3600 means that the response can be used for the next 60 minutes before it needs to fetch a new response from the origin server.

How do I set Cache-Control in HTML?

To use cache-control in HTML, you use the meta tag, e.g. The value in the content field is defined as one of the four values below. HTTP 1.1. Allowed values = PUBLIC | PRIVATE | NO-CACHE | NO-STORE.


1 Answers

One of the way to Set cache expiration is by using .htaccess file.

Below code will set expiration for it's respective file type, e.g. for CSS files expiration will be 14 days.

<IfModule mod_expires.c>    ExpiresActive on    ExpiresDefault "access plus 1 month"    ExpiresByType application/javascript "access plus 1 year"    ExpiresByType image/x-ico "access plus 1 year"    ExpiresByType image/jpg "access plus 14 days"    ExpiresByType image/jpeg "access plus 14 days"    ExpiresByType image/gif "access plus 14 days"    ExpiresByType image/png "access plus 14 days"    ExpiresByType text/css "access plus 14 days" </IfModule> 
like image 193
Shankar Prakash G Avatar answered Sep 20 '22 21:09

Shankar Prakash G