Skip to content

Commit f8710cf

Browse files
committed
Add cachebusting
1 parent 1c915ff commit f8710cf

File tree

3 files changed

+73
-16
lines changed

3 files changed

+73
-16
lines changed

.eleventy.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const fs = require('fs');
22
const inclusiveLangPlugin = require('@11ty/eleventy-plugin-inclusive-language');
3+
const cacheBuster = require('@mightyplow/eleventy-plugin-cache-buster');
34
const htmlmin = require('html-minifier');
45
const { minify } = require('terser');
56
const siteSettings = require('./src/globals/site.json');
@@ -10,6 +11,22 @@ module.exports = function (eleventyConfig) {
1011

1112
eleventyConfig.addPlugin(inclusiveLangPlugin);
1213

14+
if (process.env.ELEVENTY_ENV === 'production') {
15+
eleventyConfig.addPlugin(cacheBuster({ outputDirectory: 'dist' }));
16+
17+
eleventyConfig.addTransform('htmlmin', function (content, outputPath) {
18+
if (outputPath && outputPath.endsWith('.html')) {
19+
return htmlmin.minify(content, {
20+
useShortDoctype: true,
21+
removeComments: true,
22+
collapseWhitespace: true,
23+
});
24+
}
25+
26+
return content;
27+
});
28+
}
29+
1330
eleventyConfig.addNunjucksAsyncFilter('jsmin', async function (
1431
code,
1532
callback
@@ -43,22 +60,6 @@ module.exports = function (eleventyConfig) {
4360
},
4461
});
4562

46-
eleventyConfig.addTransform('htmlmin', function (content, outputPath) {
47-
if (
48-
process.env.ELEVENTY_ENV === 'production' &&
49-
outputPath &&
50-
outputPath.endsWith('.html')
51-
) {
52-
return htmlmin.minify(content, {
53-
useShortDoctype: true,
54-
removeComments: true,
55-
collapseWhitespace: true,
56-
});
57-
}
58-
59-
return content;
60-
});
61-
6263
return {
6364
pathPrefix: siteSettings.baseUrl,
6465
dir: {

package-lock.json

Lines changed: 55 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
@@ -23,6 +23,7 @@
2323
"devDependencies": {
2424
"@11ty/eleventy": "^0.11.0",
2525
"@11ty/eleventy-plugin-inclusive-language": "^1.0.0",
26+
"@mightyplow/eleventy-plugin-cache-buster": "^1.1.3",
2627
"@tailwindcss/typography": "^0.2.0",
2728
"autoprefixer": "^10.0.1",
2829
"cross-env": "^7.0.2",

0 commit comments

Comments
 (0)