Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use rewrite for placeholders and improve cache control #4722

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
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
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
129 changes: 8 additions & 121 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,138 +3,25 @@
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]]
from = "/"
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"
force = false
status = 302
headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"}

[[redirects]]
from = "/_/*/logo.png"
to = "/_/_placeholder/logo.png"
force = false
status = 302
headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"}

[[redirects]]
from = "/_/*/[email protected]"
to = "/_/_placeholder/[email protected]"
force = false
status = 302
headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"}

[[redirects]]
from = "/_/*/[email protected]"
to = "/_/_placeholder/[email protected]"
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 = "/_/*/[email protected]"
to = "/_/_placeholder/[email protected]"
force = false
status = 302
headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"}

[[redirects]]
from = "/_/*/[email protected]"
to = "/_/_placeholder/[email protected]"
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/_/*/[email protected]"
to = "/brands/_/_placeholder/[email protected]"
force = false
status = 302
headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"}

[[redirects]]
from = "/brands/_/*/[email protected]"
to = "/brands/_/_placeholder/[email protected]"
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/_/*/[email protected]"
to = "/brands/_/_placeholder/[email protected]"
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 = "/brands/_/*/[email protected]"
to = "/brands/_/_placeholder/[email protected]"
from = "/brands/_/*/:image"
to = "/brands/_/_placeholder/:image"
force = false
status = 302
headers = {Cache-Control = "public, max-age: 900, s-maxage=3600, must-revalidate"}
status = 200