Skip to content

Commit 7956cbc

Browse files
authored
Support ETags at server level (#231)
1 parent 93d524f commit 7956cbc

File tree

7 files changed

+48
-15
lines changed

7 files changed

+48
-15
lines changed

.github/workflows/htaccess.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
run: ./bin/build.sh test/conf/.htaccess test/build/htaccess_fixture.conf
2121

2222
- name: Test with server-configs-test
23-
uses: h5bp/server-configs-test@5.1.0
23+
uses: h5bp/server-configs-test@5.2.0
2424
with:
2525
command: test
2626
server: httpd
@@ -29,7 +29,7 @@ jobs:
2929
tests: basic-file-access:cache-busting:custom-errors:forbidden-files:enforce-gzip:precompressed-files-gzip:concatenation
3030

3131
- name: Benchmark
32-
uses: h5bp/server-configs-test@5.1.0
32+
uses: h5bp/server-configs-test@5.2.0
3333
with:
3434
command: benchmark
3535
server: httpd

.github/workflows/server.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,17 @@ jobs:
3131
"httpd.conf"
3232
3333
- name: Test with server-configs-test
34-
uses: h5bp/server-configs-test@5.1.0
34+
uses: h5bp/server-configs-test@5.2.0
3535
with:
3636
command: test
3737
server: httpd
3838
root-path: /usr/local/apache2/htdocs
3939
certs-path: /usr/local/apache2/certs
4040
configs-volumes: test/vhosts:/usr/local/apache2/vhosts;h5bp:/usr/local/apache2/h5bp;httpd.conf:/usr/local/apache2/conf/httpd.conf
41-
#tests: basic-file-access;caching;cache-busting;custom-errors;forbidden-files;enforce-gzip;precompressed-files-gzip;rewrites;ssl
42-
tests: basic-file-access;cache-busting;custom-errors;forbidden-files;enforce-gzip;precompressed-files-gzip;rewrites;ssl
41+
tests: basic-file-access;caching;cache-busting;custom-errors;forbidden-files;enforce-gzip;precompressed-files-gzip;rewrites;ssl
4342

4443
- name: Benchmark
45-
uses: h5bp/server-configs-test@5.1.0
44+
uses: h5bp/server-configs-test@5.2.0
4645
with:
4746
command: benchmark
4847
server: httpd

bin/htaccess.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ enable "h5bp/web_performance/compression.conf"
8282
disable "h5bp/web_performance/pre-compressed_content_brotli.conf"
8383
disable "h5bp/web_performance/pre-compressed_content_gzip.conf"
8484
disable "h5bp/web_performance/content_transformation.conf"
85-
enable "h5bp/web_performance/etags.conf"
85+
enable "h5bp/web_performance/no_etags.conf"
8686
enable "h5bp/web_performance/cache_expiration.conf"
8787
disable "h5bp/web_performance/file_concatenation.conf"
8888
disable "h5bp/web_performance/filename-based_cache_busting.conf"

h5bp/web_performance/etags.conf

+19-7
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,27 @@
22
# | ETags |
33
# ----------------------------------------------------------------------
44

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

11-
# `FileETag None` doesn't work in all cases.
12-
<IfModule mod_headers.c>
13-
Header unset ETag
14-
</IfModule>
24+
# (1)
25+
#DeflateAlterETag NoChange
1526

16-
FileETag None
27+
# (2)
28+
RequestHeader edit "If-None-Match" '^"((.*)-gzip)"$' '"$1", "$2"'

h5bp/web_performance/no_etags.conf

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# ----------------------------------------------------------------------
2+
# | ETags |
3+
# ----------------------------------------------------------------------
4+
5+
# Remove `ETags` as resources are sent with far-future expires headers.
6+
#
7+
# Apache `ETags` might have an unexpected behavior if `DeflateAlterETag`
8+
# can't be changed (which is the case at `.htaccess` level).
9+
#
10+
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag
11+
# https://developer.yahoo.com/performance/rules.html#etags
12+
# https://tools.ietf.org/html/rfc7232#section-2.3
13+
14+
# `FileETag None` doesn't work in all cases.
15+
<IfModule mod_headers.c>
16+
Header unset ETag
17+
</IfModule>
18+
19+
FileETag None

httpd.conf

+3
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ EnableSendfile On
154154
# Enable gzip compression.
155155
Include h5bp/web_performance/compression.conf
156156

157+
# Enable ETags validation.
158+
Include h5bp/web_performance/cache_expiration.conf
159+
157160
# Specify file cache expiration.
158161
Include h5bp/web_performance/cache_expiration.conf
159162

test/build/htaccess_fixture.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ enable "h5bp/web_performance/compression.conf"
8080
enable "h5bp/web_performance/pre-compressed_content_brotli.conf"
8181
enable "h5bp/web_performance/pre-compressed_content_gzip.conf"
8282
omit "h5bp/web_performance/content_transformation.conf"
83-
enable "h5bp/web_performance/etags.conf"
83+
enable "h5bp/web_performance/no_etags.conf"
8484
enable "h5bp/web_performance/cache_expiration.conf"
8585
enable "h5bp/web_performance/file_concatenation.conf"
8686
enable "h5bp/web_performance/filename-based_cache_busting.conf"

0 commit comments

Comments
 (0)