Node JS 搭建的 Azure Web 应用如何修改响应 Header 的 Cache-Control 字段

请按照以下步骤进行配置:

  1. 在 web.config 中配置 Cache-Control 属性:

    <configuration>
        <sytem.webServer>
            <httpProtocol>
                <customHeaders>
                    <remove name="Cache-Control" />
                    <add name="Cache-Control" value="public, max-age=99" />
                </customHeaders>
            </httpProtocol>
        </system.webServer>
    </configuration>
    
  2. 将静态内容和动态内容分开处理:

    <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
    <rule name="StaticContent">
        <action type="Rewrite" url="public{PATH_INFO}"/>
    </rule>
    <!-- All other URLs are mapped to the node.js site entry point -->
    <rule name="DynamicContent">
        <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
        </conditions>
        <action type="Rewrite" url="server.js"/>
    </rule>
    </rules>
    

参考文档