Change cache control time on an Azure site
I need to increase the header time Cache-control
for some static resources served from the Azure Website. I am using PHP as a language.
Can I do this for the whole folder? Can I do this for some file extensions (.jpg)?
You can usually do it with a simple one .htaccess
, but I don't know how to do it on Azure sites.
I don't want to use a CDN, please don't reply to this.
source to share
Azure Websites uses IIS configuration. To customize the header Cache-control
, create a file (or update the one you already have) named web.config
and put it in it
This sets max-age
up to 20 days, for example
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="20.00:00:00" />
</staticContent>
</system.webServer>
</configuration>
if you want a specific date, you can do that and it will expire on Aug 1st 2016.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseExpires" httpExpires="Mon, 01 Aug 2016 00:00:00 GMT" />
</staticContent>
</system.webServer>
</configuration>
For more details on setting clientCache
in IIS check this page http://www.iis.net/configreference/system.webserver/staticcontent/clientcache
source to share