Skip to content

Commit

Permalink
Merge pull request node-red#4817 from node-red/mermaid-caching
Browse files Browse the repository at this point in the history
Ensure mermaid.min.js is cached properly between loads of the editor
  • Loading branch information
knolleary authored Jun 28, 2024
2 parents 1b5b3f7 + 28c41e1 commit d7aa792
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,22 @@ RED.editor.mermaid = (function () {

if (!initializing) {
initializing = true
$.getScript(
'vendor/mermaid/mermaid.min.js',
function (data, stat, jqxhr) {
// Find the cache-buster:
let cacheBuster
$('script').each(function (i, el) {
if (!cacheBuster) {
const src = el.getAttribute('src')
const m = /\?v=(.+)$/.exec(src)
if (m) {
cacheBuster = m[1]
}
}
})
$.ajax({
url: `vendor/mermaid/mermaid.min.js?v=${cacheBuster}`,
dataType: "script",
cache: true,
success: function (data, stat, jqxhr) {
mermaid.initialize({
startOnLoad: false,
theme: RED.settings.get('mermaid', {}).theme
Expand All @@ -24,7 +37,7 @@ RED.editor.mermaid = (function () {
render(pending)
}
}
)
});
}
} else {
const nodes = document.querySelectorAll(selector)
Expand Down

0 comments on commit d7aa792

Please sign in to comment.