Added immutable caching to the fingerprinted media types for the ConfigReader+Properties extension in the Website service target.

This commit is contained in:
2026-08-25 16:59:07 +02:00
parent 988090a511
commit 7aee1cd949
3 changed files with 56 additions and 6 deletions
+6 -2
View File
@@ -14,10 +14,14 @@ struct AppTests {
// MARK: Constants
// Stylesheets and scripts are referenced through fingerprinted URLs, so they are served immutable.
// Referenced through fingerprinted URLs, or an immutable subset file in the case of a font, so all of these are served immutable.
private let immutableExtensions: [AssetExtension] = [
.css,
.js
.jpg,
.js,
.mp4,
.webp,
.woff2
]
// Absolute path to the copy of the package's "Resources/Static" folder made into the test bundle
@@ -61,6 +61,44 @@ struct ConfigReaderPropertiesTests {
#expect(reader(values: [.Analytics.websiteID: ""]).analytics == nil)
}
@Test(arguments: [
"shared.css",
"shared.js",
"milker-400.woff2",
"booth.mp4",
"portrait.jpg",
"portrait.webp"
])
func `cache control to mark the fingerprinted media immutable`(
file: String
) throws {
let header = try #require(reader().cacheControl.getCacheControlHeader(for: file))
#expect(header.contains("immutable"))
}
@Test(arguments: [
// The icons are exempt: a browser fetches `/favicon.ico` unversioned whatever the markup says, and the manifest names the PNGs.
"favicon.ico",
"icon-192.png",
"icon.svg"
])
func `cache control to leave the unversioned images mutable`(
file: String
) throws {
let header = try #require(reader().cacheControl.getCacheControlHeader(for: file))
#expect(!header.contains("immutable"))
}
@Test
func `cache control to have the unversioned text revalidate`() throws {
let header = try #require(reader().cacheControl.getCacheControlHeader(for: "robots.txt"))
#expect(header.contains("must-revalidate"))
#expect(!header.contains("immutable"))
}
}
// MARK: - Helpers