Use ETags instead of Last-Modified for caching
This commit is contained in:
parent
f2f8efdc1d
commit
c7a4d2fe0c
2 changed files with 17 additions and 2 deletions
12
flake.nix
12
flake.nix
|
|
@ -30,12 +30,22 @@
|
||||||
pname = "my-static-site";
|
pname = "my-static-site";
|
||||||
version = "1.0.0";
|
version = "1.0.0";
|
||||||
src = ./.;
|
src = ./.;
|
||||||
buildInputs = [ eleventy ];
|
buildInputs = with pkgs; [
|
||||||
|
eleventy
|
||||||
|
fd
|
||||||
|
coreutils
|
||||||
|
];
|
||||||
buildPhase = "eleventy";
|
buildPhase = "eleventy";
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
mkdir -p $out/
|
mkdir -p $out/
|
||||||
echo $out
|
echo $out
|
||||||
cp -r _site/* $out/
|
cp -r _site/* $out/
|
||||||
|
|
||||||
|
# Generate .etag files for cache validation
|
||||||
|
for file in $(fd --type f . "$out"); do
|
||||||
|
hash=$(md5sum "$file" | cut -d" " -f1)
|
||||||
|
echo "\"$hash\"" > "$file.etag"
|
||||||
|
done;
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,12 @@ in
|
||||||
enable = true;
|
enable = true;
|
||||||
# Needs `http://` prefix so that it does not try to request TLS certificates and redirect to 443
|
# Needs `http://` prefix so that it does not try to request TLS certificates and redirect to 443
|
||||||
virtualHosts."http://${site-url}".extraConfig = ''
|
virtualHosts."http://${site-url}".extraConfig = ''
|
||||||
file_server
|
header {
|
||||||
|
-Last-Modified
|
||||||
|
}
|
||||||
|
file_server {
|
||||||
|
etag_file_extensions .etag
|
||||||
|
}
|
||||||
root * ${inputs.our-site.packages."${pkgs.system}".default}
|
root * ${inputs.our-site.packages."${pkgs.system}".default}
|
||||||
encode gzip
|
encode gzip
|
||||||
'';
|
'';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue