Use rewrite for placeholders and improve cache control (#4722)

This commit is contained in:
Steve Repsher 2023-10-24 17:33:13 -04:00 committed by GitHub
parent ce098e0aee
commit c7ed0d70aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 128 deletions

View file

@ -68,15 +68,11 @@ For example: <`https://brands.home-assistant.io/_/[domain]/icon.png`>
### Caching
All icons are cached on the client-side browser end for 900 seconds, and cached
by Cloudflare for 604800 seconds.
All icons and logos are cached by browsers for 7 days, so additions and changes may take time to reach all users. This gives users the full benefits of local caching with minimal revalidation, and protects against missing content during an internet outage.
Placeholder images are excepted from this. Placeholder images have a 900 seconds
cache on the client-side and are cached for 1 hour on Cloudflare. This allows
us to replace placeholder images within an acceptable time frame without losing
our cache.
Images are simultaneously cached by Cloudflare for 24 hours. This allows changes to begin being distributed to users relatively quickly without losing the CDN benefits. It also guarantees a simple refresh (F5) will bring content no more than 1 day old.
Image additions and changes may take time to take effect due to caching. The cache is fully flushed in each major version of Home Assistant Core.
The Cloudflare cache is also fully flushed in each major version of Home Assistant Core.
## Image specification

View file

@ -3,21 +3,9 @@
command = "bash ./scripts/build.sh"
[[headers]]
for = "/_/_placeholder/*.png"
for = "/*"
[headers.values]
Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"
Access-Control-Allow-Origin = "*"
[[headers]]
for = "/*.png"
[headers.values]
Cache-Control = "public, max-age: 900, s-maxage=604800, must-revalidate"
Access-Control-Allow-Origin = "*"
[[headers]]
for = "/domains.json"
[headers.values]
Cache-Control = "public, max-age: 900, s-maxage=604800, must-revalidate"
Cache-Control = "public, max-age=604800, s-maxage=86400, stale-while-revalidate=604800"
Access-Control-Allow-Origin = "*"
[[redirects]]
@ -25,116 +13,15 @@
to = "https://github.com/home-assistant/brands"
force = true
status = 301
headers = {Cache-Control = "public, max-age: 900, s-maxage=604800, must-revalidate"}
[[redirects]]
from = "/_/*/icon.png"
to = "/_/_placeholder/icon.png"
from = "/_/*/:image"
to = "/_/_placeholder/:image"
force = false
status = 302
headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"}
status = 200
[[redirects]]
from = "/_/*/logo.png"
to = "/_/_placeholder/logo.png"
from = "/brands/_/*/:image"
to = "/brands/_/_placeholder/:image"
force = false
status = 302
headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"}
[[redirects]]
from = "/_/*/icon@2x.png"
to = "/_/_placeholder/icon@2x.png"
force = false
status = 302
headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"}
[[redirects]]
from = "/_/*/logo@2x.png"
to = "/_/_placeholder/logo@2x.png"
force = false
status = 302
headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"}
[[redirects]]
from = "/_/*/dark_icon.png"
to = "/_/_placeholder/icon.png"
force = false
status = 302
headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"}
[[redirects]]
from = "/_/*/dark_logo.png"
to = "/_/_placeholder/logo.png"
force = false
status = 302
headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"}
[[redirects]]
from = "/_/*/dark_icon@2x.png"
to = "/_/_placeholder/icon@2x.png"
force = false
status = 302
headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"}
[[redirects]]
from = "/_/*/dark_logo@2x.png"
to = "/_/_placeholder/logo@2x.png"
force = false
status = 302
headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"}
[[redirects]]
from = "/brands/_/*/icon.png"
to = "/brands/_/_placeholder/icon.png"
force = false
status = 302
headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"}
[[redirects]]
from = "/brands/_/*/logo.png"
to = "/brands/_/_placeholder/logo.png"
force = false
status = 302
headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"}
[[redirects]]
from = "/brands/_/*/icon@2x.png"
to = "/brands/_/_placeholder/icon@2x.png"
force = false
status = 302
headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"}
[[redirects]]
from = "/brands/_/*/logo@2x.png"
to = "/brands/_/_placeholder/logo@2x.png"
force = false
status = 302
headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"}
[[redirects]]
from = "/brands/_/*/dark_icon.png"
to = "/brands/_/_placeholder/icon.png"
force = false
status = 302
headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"}
[[redirects]]
from = "/brands/_/*/dark_logo.png"
to = "/brands/_/_placeholder/logo.png"
force = false
status = 302
headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"}
[[redirects]]
from = "/brands/_/*/dark_icon@2x.png"
to = "/brands/_/_placeholder/icon@2x.png"
force = false
status = 302
headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"}
[[redirects]]
from = "/brands/_/*/dark_logo@2x.png"
to = "/brands/_/_placeholder/logo@2x.png"
force = false
status = 302
headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"}
status = 200