From 941e018055c65b6193b0c674bae71f298c126cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Mon, 14 Sep 2026 13:18:03 +0200 Subject: [PATCH] Add `Cache-Control` header to cache static files for 1 day --- Dockerfile | 2 +- README.md | 2 -- tests/integration.bash | 12 ++++++++++++ www/.htaccess | 3 +++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2e02778..8a04f87 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,7 @@ COPY www/ www/ RUN vendor/bin/sculpin generate FROM php:8.1-apache -RUN ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled +RUN ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-available/headers.load /etc/apache2/mods-enabled COPY --from=build /app/build/ /var/www/html/ HEALTHCHECK --start-period=1m --start-interval=0.1s --interval=1h \ CMD ["curl", "-I", "--no-progress-meter", "http://localhost/"] diff --git a/README.md b/README.md index eafbecb..3f12a8c 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,6 @@ directory behind your favorite web server (Apache + PHP-FPM etc.). Additionally, this should be deployed behind a reverse proxy (nginx) or CDN (Bunny CDN) that is responsible for HTTPS certificate handling and forcing HTTPS redirects. -Additionally, Apache has been configured to cache static files for 1 day. - The live website is deployed by pushing the contents of the `build/` directory to the `live` branch like this: diff --git a/tests/integration.bash b/tests/integration.bash index d33e299..a81fe94 100755 --- a/tests/integration.bash +++ b/tests/integration.bash @@ -20,6 +20,7 @@ match() { curl -v $base/ match "HTTP/.* 200" match -iE "Content-Type: text/html(;.*)?$" +match -iE "Cache-Control: max-age=86400$" curl -v $base/index.html match "HTTP/.* 302" @@ -34,6 +35,7 @@ match "HTTP/.* 404" curl -v $base/blog match "HTTP/.* 200" match -iE "Content-Type: text/html(;.*)?$" +match -iE "Cache-Control: max-age=86400$" curl -v $base/blog.html match "HTTP/.* 302" @@ -99,4 +101,14 @@ curl -v $base/contact/ match "HTTP/.* 302" match -iE "Location: $redir/contact$" +curl -v $base/posts.atom +match "HTTP/.* 200" +match -iE "Content-Type: application/atom\+xml$" +match -iE "Cache-Control: max-age=86400$" + +curl -v $base/src/tailwind.min.css +match "HTTP/.* 200" +match -iE "Content-Type: text/css$" +match -iE "Cache-Control: max-age=86400$" + echo "OK ($n)" diff --git a/www/.htaccess b/www/.htaccess index 4aeb120..0f764de 100644 --- a/www/.htaccess +++ b/www/.htaccess @@ -60,3 +60,6 @@ Redirect /psocksd-0.3.4.phar https://github.com/clue/psocksd/releases/download/v Redirect /psocksd-0.3.3.phar https://github.com/clue/psocksd/releases/download/v0.3.3/psocksd.phar Redirect /psocksd-0.3.2.phar https://github.com/clue/psocksd/releases/download/v0.3.2/psocksd.phar Redirect /psocksd-0.3.1.phar https://github.com/clue/psocksd/releases/download/v0.3.1/psocksd.phar + +# all files should be cached for 1 day, otherwise any intermediaries may apply their own caching rules +Header set Cache-Control "max-age=86400"