riptano / docs-ui

The UI and theme for DataStax Docs.
https://riptano.github.io/docs-ui/
Mozilla Public License 2.0
2 stars 0 forks source link

Implement cache busting with an assets-manifest and hashed js/css file names #137

Closed colegoldsmith closed 1 month ago

colegoldsmith commented 1 month ago

How does this work?

I've implemented gulp-hash into the gulp build pipeline to do two things for all the js and css files.

To make use of these gulp-hash additions I've implemented a new handlebars helper that allows the templates to read that assets-manifest.json file and insert the new hashed file name using the unhashed file name as the lookup key. For example the link for the main site.css file

<link rel="stylesheet" href="{{{uiRootPath}}}/{{{assets-manifest 'css/site.css' }}}">

// When Antora builds the html files that handlebars template turns into this

<link rel="stylesheet" href="_/css/site-9a3dd424.css">

End Result

Any time we release a new UI bundle the js/css files will get a new hash and thus a new file name. This forces all client browsers to download the new version of the file instead of using the cached version

mlr commented 1 month ago

UI bundle preview build failure! :x:

[02:09:39] Using gulpfile ~/work/docs-ui/docs-ui/gulpfile.js [02:09:39] Starting 'lint'... [02:09:40] /home/runner/work/docs-ui/docs-ui/gulpfile.js 3:9 error 'parallel' is assigned a value but never used no-unused-vars /home/runner/work/docs-ui/docs-ui/gulp.d/tasks/build-preview-pages.js 22:1 warning This line has a length of 127. Maximum allowed is 120 max-len ✖ 2 problems (1 error, 1 warning) [02:09:40] 'lint' errored after 1.13 s [02:09:40] ESLintError in plugin "gulp-eslint" Message: Failed with 1 error

mlr commented 1 month ago

Antora site build failure! :x:

[02:10:15] Using gulpfile ~/work/datastax-docs-site/datastax-docs-site/ui-bundle-preview/gulpfile.js [02:10:15] Starting 'bundle'... [02:10:15] Starting 'clean'... [02:10:15] Finished 'clean' after 12 ms [02:10:15] Starting 'lint'... [02:10:17] /home/runner/work/datastax-docs-site/datastax-docs-site/ui-bundle-preview/gulpfile.js 3:9 error 'parallel' is assigned a value but never used no-unused-vars /home/runner/work/datastax-docs-site/datastax-docs-site/ui-bundle-preview/gulp.d/tasks/build-preview-pages.js 22:1 warning This line has a length of 127. Maximum allowed is 120 max-len ✖ 2 problems (1 error, 1 warning) [02:10:17] 'lint' errored after 1.7 s [02:10:17] ESLintError in plugin "gulp-eslint" Message: Failed with 1 error [02:10:17] 'bundle' errored after 1.72 s

mlr commented 1 month ago

UI bundle preview build successful! :white_check_mark: Deploying preview to GitHub Pages. Deployment successful! View preview

mlr commented 1 month ago

UI bundle preview build successful! :white_check_mark: Deploying preview to GitHub Pages. Deployment successful! View preview