Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the cache-control time on Azure Website

I need to increase the time of the Cache-control header for some static resources served from an Azure Website. I am using PHP as the language.

Can I do it for an entire folder? Can I do it for some file extesions (.jpg) ?

Normally you can do this with a simple .htaccess but I don't know how to do it in Azure Websites.

I dont want to use the CDN please don't answer that.

like image 915
Ricardo Blanch Avatar asked Dec 03 '25 11:12

Ricardo Blanch


1 Answers

Azure Websites uses IIS configuration. To configure Cache-control header create a file (or update the one you may already have) called web.config and put this in it

This sets max-age 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 certain date you can do this, which sets it to expire on August 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 about the clientCache setting in IIS check this page http://www.iis.net/configreference/system.webserver/staticcontent/clientcache

like image 68
ahmelsayed Avatar answered Dec 05 '25 00:12

ahmelsayed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!