简体   繁体   English

更改Azure网站上的缓存控制时间

[英]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. 我需要为Azure网站提供的一些静态资源增加Cache-control标头的时间。 I am using PHP as the language. 我使用PHP作为语言。

Can I do it for an entire folder? 我可以为整个文件夹执行此操作吗? Can I do it for some file extesions (.jpg) ? 我可以为一些文件扩展(.jpg)吗?

Normally you can do this with a simple .htaccess but I don't know how to do it in Azure Websites. 通常,您可以使用简单的.htaccess执行此操作,但我不知道如何在Azure网站中执行此操作。

I dont want to use the CDN please don't answer that. 我不想使用CDN请不要回答。

Azure Websites uses IIS configuration. Azure网站使用IIS配置。 To configure Cache-control header create a file (or update the one you may already have) called web.config and put this in it 要配置Cache-control标头,请创建一个名为web.config的文件(或更新您可能已经拥有的文件)并将其放入其中

This sets max-age to 20 days for example 例如,这将max-age为20天

<?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 如果你想要一个特定日期,你可以这样做,这将使它在2016年8月1日到期

<?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 有关IIS中clientCache设置的更多信息,请查看此页面http://www.iis.net/configreference/system.webserver/staticcontent/clientcache

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM