Skip to content

Commit

Permalink
Support ETags at server level (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoColomb authored Feb 13, 2022
1 parent 93d524f commit 7956cbc
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/htaccess.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
run: ./bin/build.sh test/conf/.htaccess test/build/htaccess_fixture.conf

- name: Test with server-configs-test
uses: h5bp/server-configs-test@5.1.0
uses: h5bp/server-configs-test@5.2.0
with:
command: test
server: httpd
Expand All @@ -29,7 +29,7 @@ jobs:
tests: basic-file-access:cache-busting:custom-errors:forbidden-files:enforce-gzip:precompressed-files-gzip:concatenation

- name: Benchmark
uses: h5bp/server-configs-test@5.1.0
uses: h5bp/server-configs-test@5.2.0
with:
command: benchmark
server: httpd
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,17 @@ jobs:
"httpd.conf"
- name: Test with server-configs-test
uses: h5bp/server-configs-test@5.1.0
uses: h5bp/server-configs-test@5.2.0
with:
command: test
server: httpd
root-path: /usr/local/apache2/htdocs
certs-path: /usr/local/apache2/certs
configs-volumes: test/vhosts:/usr/local/apache2/vhosts;h5bp:/usr/local/apache2/h5bp;httpd.conf:/usr/local/apache2/conf/httpd.conf
#tests: basic-file-access;caching;cache-busting;custom-errors;forbidden-files;enforce-gzip;precompressed-files-gzip;rewrites;ssl
tests: basic-file-access;cache-busting;custom-errors;forbidden-files;enforce-gzip;precompressed-files-gzip;rewrites;ssl
tests: basic-file-access;caching;cache-busting;custom-errors;forbidden-files;enforce-gzip;precompressed-files-gzip;rewrites;ssl

- name: Benchmark
uses: h5bp/server-configs-test@5.1.0
uses: h5bp/server-configs-test@5.2.0
with:
command: benchmark
server: httpd
Expand Down
2 changes: 1 addition & 1 deletion bin/htaccess.conf
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ enable "h5bp/web_performance/compression.conf"
disable "h5bp/web_performance/pre-compressed_content_brotli.conf"
disable "h5bp/web_performance/pre-compressed_content_gzip.conf"
disable "h5bp/web_performance/content_transformation.conf"
enable "h5bp/web_performance/etags.conf"
enable "h5bp/web_performance/no_etags.conf"
enable "h5bp/web_performance/cache_expiration.conf"
disable "h5bp/web_performance/file_concatenation.conf"
disable "h5bp/web_performance/filename-based_cache_busting.conf"
26 changes: 19 additions & 7 deletions h5bp/web_performance/etags.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,27 @@
# | ETags |
# ----------------------------------------------------------------------

# Remove `ETags` as resources are sent with far-future expires headers.
# Enable ETags.
#
# (1) Don't change the ETag on a compressed response.
# Default prevents serving "HTTP Not Modified" (304) responses to
# conditional requests for compressed content.
# https://httpd.apache.org/docs/current/mod/mod_deflate.html#deflatealteretag
#
# (2) `DeflateAlterETag` is not supported on version older than 2.5.
# As an alternative of the previous directive, this one is used to keep
# both the original ETag and the modified one when compressing responses.
# https://symfony.com/doc/current/http_cache/validation.html
#
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag
# https://developer.yahoo.com/performance/rules.html#etags
# https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching
# https://tools.ietf.org/html/rfc7232#section-2.3
# https://httpd.apache.org/docs/current/mod/core.html#fileetag

FileETag MTime Size

# `FileETag None` doesn't work in all cases.
<IfModule mod_headers.c>
Header unset ETag
</IfModule>
# (1)
#DeflateAlterETag NoChange

FileETag None
# (2)
RequestHeader edit "If-None-Match" '^"((.*)-gzip)"$' '"$1", "$2"'
19 changes: 19 additions & 0 deletions h5bp/web_performance/no_etags.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ----------------------------------------------------------------------
# | ETags |
# ----------------------------------------------------------------------

# Remove `ETags` as resources are sent with far-future expires headers.
#
# Apache `ETags` might have an unexpected behavior if `DeflateAlterETag`
# can't be changed (which is the case at `.htaccess` level).
#
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag
# https://developer.yahoo.com/performance/rules.html#etags
# https://tools.ietf.org/html/rfc7232#section-2.3

# `FileETag None` doesn't work in all cases.
<IfModule mod_headers.c>
Header unset ETag
</IfModule>

FileETag None
3 changes: 3 additions & 0 deletions httpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ EnableSendfile On
# Enable gzip compression.
Include h5bp/web_performance/compression.conf

# Enable ETags validation.
Include h5bp/web_performance/cache_expiration.conf

# Specify file cache expiration.
Include h5bp/web_performance/cache_expiration.conf

Expand Down
2 changes: 1 addition & 1 deletion test/build/htaccess_fixture.conf
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ enable "h5bp/web_performance/compression.conf"
enable "h5bp/web_performance/pre-compressed_content_brotli.conf"
enable "h5bp/web_performance/pre-compressed_content_gzip.conf"
omit "h5bp/web_performance/content_transformation.conf"
enable "h5bp/web_performance/etags.conf"
enable "h5bp/web_performance/no_etags.conf"
enable "h5bp/web_performance/cache_expiration.conf"
enable "h5bp/web_performance/file_concatenation.conf"
enable "h5bp/web_performance/filename-based_cache_busting.conf"

0 comments on commit 7956cbc

Please sign in to comment.