Skip to content

Commit a6bb888

Browse files
Merge pull request #3879 from IgniteUI/pmoleri/improve-spa-caching
Improve SPA caching
2 parents 2a49e69 + 9b46638 commit a6bb888

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

projects/app-crm/web.config

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<add enabled="true" mimeType="message/*"/>
1616
<add enabled="true" mimeType="application/javascript"/>
1717
<add enabled="true" mimeType="application/json"/>
18+
<add enabled="true" mimeType="image/svg+xml"/>
1819
<add enabled="false" mimeType="*/*"/>
1920
</staticTypes>
2021
</httpCompression>
@@ -29,9 +30,26 @@
2930
<action type="Rewrite" url="/angular-demos/" />
3031
</rule>
3132
</rules>
33+
<outboundRules>
34+
<rule name="Cache immutable files" preCondition="IsImmutable">
35+
<match serverVariable="RESPONSE_Cache-Control" pattern=".*" />
36+
<action type="Rewrite" value="public, max-age=31536000, immutable" />
37+
</rule>
38+
<preConditions>
39+
<preCondition name="IsImmutable" logicalGrouping="MatchAny">
40+
<add input="{REQUEST_URI}" pattern="styles-.*\.css$" />
41+
<add input="{REQUEST_URI}" pattern="chunk-.*\.js$" />
42+
<add input="{REQUEST_URI}" pattern="main-.*\.js$" />
43+
<add input="{REQUEST_URI}" pattern="polyfills-.*\.js$" />
44+
<add input="{REQUEST_URI}" pattern="/media/.*" />
45+
</preCondition>
46+
</preConditions>
47+
</outboundRules>
3248
</rewrite>
3349
<staticContent>
34-
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
50+
<!-- 1 hour public cache for regular static assets -->
51+
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="0.01:00:00" cacheControlCustom="public" />
52+
3553
<remove fileExtension=".json" />
3654
<remove fileExtension=".csv" />
3755
<remove fileExtension=".shp" />
@@ -52,4 +70,12 @@
5270
</customHeaders>
5371
</httpProtocol>
5472
</system.webServer>
73+
<location path="index.html">
74+
<system.webServer>
75+
<staticContent>
76+
<!-- Short-lived cache for index.html -->
77+
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="0.00:05:00" cacheControlCustom="public" />
78+
</staticContent>
79+
</system.webServer>
80+
</location>
5581
</configuration>

web.config

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<add enabled="true" mimeType="message/*"/>
1616
<add enabled="true" mimeType="application/javascript"/>
1717
<add enabled="true" mimeType="application/json"/>
18+
<add enabled="true" mimeType="image/svg+xml"/>
1819
<add enabled="false" mimeType="*/*"/>
1920
</staticTypes>
2021
</httpCompression>
@@ -31,11 +32,28 @@
3132
<rule name="Angular Root Redirect" enabled="true" stopProcessing="true">
3233
<match url="^/?$" />
3334
<action type="Redirect" url="/products/ignite-ui-angular/getting-started" redirectType="Permanent" />
34-
</rule>
35+
</rule>
3536
</rules>
37+
<outboundRules>
38+
<rule name="Cache immutable files" preCondition="IsImmutable">
39+
<match serverVariable="RESPONSE_Cache-Control" pattern=".*" />
40+
<action type="Rewrite" value="public, max-age=31536000, immutable" />
41+
</rule>
42+
<preConditions>
43+
<preCondition name="IsImmutable" logicalGrouping="MatchAny">
44+
<add input="{REQUEST_URI}" pattern="styles-.*\.css$" />
45+
<add input="{REQUEST_URI}" pattern="chunk-.*\.js$" />
46+
<add input="{REQUEST_URI}" pattern="main-.*\.js$" />
47+
<add input="{REQUEST_URI}" pattern="polyfills-.*\.js$" />
48+
<add input="{REQUEST_URI}" pattern="/media/.*" />
49+
</preCondition>
50+
</preConditions>
51+
</outboundRules>
3652
</rewrite>
3753
<staticContent>
38-
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
54+
<!-- 1 hour public cache for regular static assets -->
55+
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="0.01:00:00" cacheControlCustom="public" />
56+
3957
<remove fileExtension=".json" />
4058
<remove fileExtension=".csv" />
4159
<remove fileExtension=".shp" />
@@ -56,4 +74,12 @@
5674
</customHeaders>
5775
</httpProtocol>
5876
</system.webServer>
77+
<location path="index.html">
78+
<system.webServer>
79+
<staticContent>
80+
<!-- Short-lived cache for index.html -->
81+
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="0.00:05:00" cacheControlCustom="public" />
82+
</staticContent>
83+
</system.webServer>
84+
</location>
5985
</configuration>

0 commit comments

Comments
 (0)