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


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

                    <remove name="Cache-Control" />
                    <add name="Cache-Control" value="public, max-age=99" />
  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}"/>
    <!-- All other URLs are mapped to the node.js site entry point -->
    <rule name="DynamicContent">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
        <action type="Rewrite" url="server.js"/>