Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 64 additions & 1 deletion web.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@
<configuration>

<system.webServer>
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
<dynamicTypes>
<add enabled="true" mimeType="text/*"/>
<add enabled="true" mimeType="message/*"/>
<add enabled="true" mimeType="application/javascript"/>
<add enabled="true" mimeType="application/json"/>
<add enabled="false" mimeType="*/*"/>
</dynamicTypes>
<staticTypes>
<add enabled="true" mimeType="text/*"/>
<add enabled="true" mimeType="message/*"/>
<add enabled="true" mimeType="application/javascript"/>
<add enabled="true" mimeType="application/json"/>
<add enabled="true" mimeType="image/svg+xml"/>
<add enabled="false" mimeType="*/*"/>
</staticTypes>
</httpCompression>
<rewrite>
<rules>
<rule name="Angular Routes" stopProcessing="true">
Expand All @@ -13,7 +31,52 @@
<action type="Rewrite" url="./index.html" />
</rule>
</rules>
<outboundRules>
<rule name="Cache immutable files" preCondition="IsImmutable">
<match serverVariable="RESPONSE_Cache-Control" pattern=".*" />
<action type="Rewrite" value="public, max-age=31536000, immutable" />
</rule>
<preConditions>
<preCondition name="IsImmutable" logicalGrouping="MatchAny">
<add input="{REQUEST_URI}" pattern="styles-.*\.css$" />
<add input="{REQUEST_URI}" pattern="chunk-.*\.js$" />
<add input="{REQUEST_URI}" pattern="main-.*\.js$" />
<add input="{REQUEST_URI}" pattern="polyfills-.*\.js$" />
<add input="{REQUEST_URI}" pattern="/media/.*" />
</preCondition>
</preConditions>
Comment on lines +38 to +47
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is a Server Side Rendered app and the index.html cache rule doesn't work in this case.

We can add the following rule to match all 200 HTML pages.

Suggested change
</rule>
<preConditions>
<preCondition name="IsImmutable" logicalGrouping="MatchAny">
<add input="{REQUEST_URI}" pattern="styles-.*\.css$" />
<add input="{REQUEST_URI}" pattern="chunk-.*\.js$" />
<add input="{REQUEST_URI}" pattern="main-.*\.js$" />
<add input="{REQUEST_URI}" pattern="polyfills-.*\.js$" />
<add input="{REQUEST_URI}" pattern="/media/.*" />
</preCondition>
</preConditions>
</rule>
<rule name="Cache SSR HTML pages" preCondition="IsHTMLResponse">
<match serverVariable="RESPONSE_Cache-Control" pattern=".*" />
<action type="Rewrite" value="public, max-age=300" />
</rule>
<preConditions>
<preCondition name="IsImmutable" logicalGrouping="MatchAny">
<add input="{REQUEST_URI}" pattern="styles-.*\.css$" />
<add input="{REQUEST_URI}" pattern="chunk-.*\.js$" />
<add input="{REQUEST_URI}" pattern="main-.*\.js$" />
<add input="{REQUEST_URI}" pattern="polyfills-.*\.js$" />
<add input="{REQUEST_URI}" pattern="/media/.*" />
</preCondition>
<preCondition name="IsHTMLResponse" logicalGrouping="MatchAll">
<add input="{RESPONSE_STATUS}" pattern="^200$" />
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>

</outboundRules>
</rewrite>
</system.webServer>
<staticContent>
<!-- 1 hour public cache for regular static assets -->
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="0.01:00:00" cacheControlCustom="public" />

<remove fileExtension=".json" />
<remove fileExtension=".csv" />
<remove fileExtension=".shp" />
<remove fileExtension=".dbf" />
<remove fileExtension=".itf" />
<remove fileExtension=".svg" />

<mimeMap fileExtension=".json" mimeType="application/json;charset=UTF-8;" />
<mimeMap fileExtension=".csv" mimeType="application/csv;charset=UTF-8;" />
<mimeMap fileExtension=".shp" mimeType="application/octet-stream" />
<mimeMap fileExtension=".dbf" mimeType="application/octet-stream" />
<mimeMap fileExtension=".itf" mimeType="application/octet-stream" />
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
</staticContent>
<httpProtocol>
<customHeaders>
<add name="X-XSS-Protection" value="0" />
</customHeaders>
</httpProtocol>
</system.webServer>
<location path="index.html">
<system.webServer>
<staticContent>
<!-- Short-lived cache for index.html -->
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="0.00:05:00" cacheControlCustom="public" />
</staticContent>
</system.webServer>
</location>
</configuration>