Restore caching busting functionality without using explict version number

Fixes #4503
4503-fix-cache-busting
Nick O'Leary 2024-01-05 23:13:30 +00:00
parent f0a9b0cf69
commit d7345d5bc6
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 12 additions and 8 deletions

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ **/
const crypto = require('crypto')
var express = require('express'); var express = require('express');
var fs = require("fs"); var fs = require("fs");
var path = require("path"); var path = require("path");
@ -28,6 +29,8 @@ var editorClientDir = path.dirname(require.resolve("@node-red/editor-client"));
var defaultNodeIcon = path.join(editorClientDir,"public","red","images","icons","arrow-in.svg"); var defaultNodeIcon = path.join(editorClientDir,"public","red","images","icons","arrow-in.svg");
var editorTemplatePath = path.join(editorClientDir,"templates","index.mst"); var editorTemplatePath = path.join(editorClientDir,"templates","index.mst");
var editorTemplate; var editorTemplate;
const version = require(path.join(editorClientDir,"package.json")).version
const cacheBuster = crypto.createHash('md5').update(version).digest("hex").substring(0,12)
module.exports = { module.exports = {
init: function(_runtimeAPI) { init: function(_runtimeAPI) {
@ -99,6 +102,7 @@ module.exports = {
} }
res.send(Mustache.render(editorTemplate,{ res.send(Mustache.render(editorTemplate,{
sessionMessages, sessionMessages,
cacheBuster,
...await theme.context() ...await theme.context()
})); }));
}, },

View File

@ -24,24 +24,24 @@
<title>{{ page.title }}</title> <title>{{ page.title }}</title>
<link rel="icon" type="image/png" href="{{ page.favicon }}"> <link rel="icon" type="image/png" href="{{ page.favicon }}">
<link rel="mask-icon" href="{{ page.tabicon.icon }}" color="{{ page.tabicon.colour }}"> <link rel="mask-icon" href="{{ page.tabicon.icon }}" color="{{ page.tabicon.colour }}">
<link rel="stylesheet" href="vendor/jquery/css/base/jquery-ui.min.css?v={{ page.version }}"> <link rel="stylesheet" href="vendor/jquery/css/base/jquery-ui.min.css?v={{ cacheBuster }}">
<link rel="stylesheet" href="vendor/font-awesome/css/font-awesome.min.css?v={{ page.version }}"> <link rel="stylesheet" href="vendor/font-awesome/css/font-awesome.min.css?v={{ cacheBuster }}">
<link rel="stylesheet" href="red/style.min.css?v={{ page.version }}"> <link rel="stylesheet" href="red/style.min.css?v={{ cacheBuster }}">
{{#page.css}} {{#page.css}}
<link rel="stylesheet" href="{{.}}"> <link rel="stylesheet" href="{{.}}">
{{/page.css}} {{/page.css}}
{{#asset.vendorMonaco}} {{#asset.vendorMonaco}}
<link rel="stylesheet" href="vendor/monaco/style.css?v={{ page.version }}"> <link rel="stylesheet" href="vendor/monaco/style.css?v={{ cacheBuster }}">
{{/asset.vendorMonaco}} {{/asset.vendorMonaco}}
</head> </head>
<body spellcheck="false"> <body spellcheck="false">
<div id="red-ui-editor"></div> <div id="red-ui-editor"></div>
<script src="vendor/vendor.js?v={{ page.version }}"></script> <script src="vendor/vendor.js?v={{ cacheBuster }}"></script>
{{#asset.vendorMonaco}} {{#asset.vendorMonaco}}
<script src="{{ asset.vendorMonaco }}?v={{ page.version }}"></script> <script src="{{ asset.vendorMonaco }}?v={{ cacheBuster }}"></script>
{{/asset.vendorMonaco}} {{/asset.vendorMonaco}}
<script src="{{ asset.red }}?v={{ page.version }}"></script> <script src="{{ asset.red }}?v={{ cacheBuster }}"></script>
<script src="{{ asset.main }}?v={{ page.version }}"></script> <script src="{{ asset.main }}?v={{ cacheBuster }}"></script>
{{# page.scripts }} {{# page.scripts }}
<script src="{{.}}"></script> <script src="{{.}}"></script>
{{/ page.scripts }} {{/ page.scripts }}