With .htaccess
(which is recommended)
First of all, create a file called .htaccess
and send to the root of your site (public_html).
Control the Cache
Inside the file insert the following code:
#5 dias de cache
# O cabeçalho "pragma" é para compatibilidade com o IE
<FilesMatch "(css|js)$">
Header set Cache-Control "max-age=432000, public, must-revalidate"
Header set Pragma "max-age=432000, public, must-revalidate"
</FilesMatch>
This way when a person accesses your site, the cache will be stored for 5 days, after 5 days, if the person accesses again, the cache will be updated, that is, a new version of your cache will be downloaded.
In the above example, 5 days of caching was given. See below for other examples.
Before you go on know, um dia tem 86.400 segundos
.
That is, if you want the cache to last only 2 days, multiply 2x 86400 seconds which is equal to: 172800 seconds.
Then in the code above replace: "max-age=432000
for "max-age=172800
and your cache will last 2 days.
Disabling the Cache
To disable the cache just replace in the first mentioned code "max-age=432000
for "max-age=0
this way you will have your Cache disabled.
The final example will be:
#Sem cache
# O cabeçalho "pragma" é para compatibilidade com o IE
<FilesMatch "(css|js)$">
Header set Cache-Control "max-age=0, public, must-revalidate"
Header set Pragma "max-age=0, public, must-revalidate"
</FilesMatch>
Observing: i configured the above code only for files .css
and .js
(which is what is usually kept as cache),
If you want to add more extensions, like images, etc....
Just add in the code above the desired extension, more precisely in:
<FilesMatch "(css|js)$">
To add images the cache settings just leave it so:
<FilesMatch "(css|js|png|jpeg|ico|gif)$">
You should separate the extensions with |
.
Will be of this you’re looking for?
– Omni