Skip to content

Commit 4f02e1b

Browse files
committed
Add hash fingerprinting for asset caching
1 parent cb47ae2 commit 4f02e1b

4 files changed

Lines changed: 137 additions & 1 deletion

File tree

.eleventy.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const markdownIt = require("markdown-it");
22
const pluginRss = require("@11ty/eleventy-plugin-rss");
3+
const cacheBuster = require("@mightyplow/eleventy-plugin-cache-buster");
34
const fs = require("fs");
45
const path = require("path");
56
const { generateImage } = require("./src/_11ty/images");
@@ -41,6 +42,7 @@ module.exports = function(eleventyConfig) {
4142
eleventyConfig.addPassthroughCopy("src/_scripts/microblog-cards.js");
4243
eleventyConfig.addPassthroughCopy("src/favicon.ico");
4344
eleventyConfig.addPassthroughCopy("src/robots.txt");
45+
eleventyConfig.addPassthroughCopy("src/.htaccess");
4446
eleventyConfig.addPassthroughCopy("src/assets");
4547
eleventyConfig.addPassthroughCopy("src/admin");
4648

@@ -82,6 +84,11 @@ module.exports = function(eleventyConfig) {
8284
/* Enable RSS */
8385
eleventyConfig.addPlugin(pluginRss);
8486

87+
/* Cache busting for CSS/JS assets */
88+
eleventyConfig.addPlugin(cacheBuster({
89+
outputDirectory: "_site"
90+
}));
91+
8592
/* Date formatting filter */
8693
eleventyConfig.addFilter("formatDate", (date) => {
8794
const d = new Date(date);

package-lock.json

Lines changed: 109 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"dependencies": {
1515
"@11ty/eleventy": "^2.0.0",
1616
"@11ty/eleventy-img": "^6.0.4",
17+
"@mightyplow/eleventy-plugin-cache-buster": "^1.1.3",
1718
"markdown-it": "^13.0.2"
1819
},
1920
"devDependencies": {

src/.htaccess

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
1-
ErrorDocument 404 /404.html
1+
ErrorDocument 404 /404.html
2+
3+
# Cache static assets (safe with cache-busting enabled)
4+
<IfModule mod_expires.c>
5+
ExpiresActive On
6+
ExpiresByType image/webp "access plus 1 year"
7+
ExpiresByType image/png "access plus 1 year"
8+
ExpiresByType image/jpeg "access plus 1 year"
9+
ExpiresByType image/svg+xml "access plus 1 year"
10+
ExpiresByType text/css "access plus 1 year"
11+
ExpiresByType application/javascript "access plus 1 year"
12+
ExpiresByType font/woff2 "access plus 1 year"
13+
ExpiresByType font/woff "access plus 1 year"
14+
</IfModule>
15+
16+
<IfModule mod_headers.c>
17+
<FilesMatch "\.(css|js|webp|png|jpg|woff2)$">
18+
Header set Cache-Control "public, max-age=31536000, immutable"
19+
</FilesMatch>
20+
</IfModule>

0 commit comments

Comments
 (0)