Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/StaticCaching/Cachers/FileCacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,18 @@ public function getNocacheJs(): string

$default = <<<EOT
(function() {
var els = document.getElementsByClassName('nocache');
var map = {};
for (var i = 0; i < els.length; i++) {
var section = els[i].getAttribute('data-nocache');
map[section] = els[i];
function createMap() {
var map = {};
var els = document.getElementsByClassName('nocache');
for (var i = 0; i < els.length; i++) {
var section = els[i].getAttribute('data-nocache');
map[section] = els[i];
}
return map;
}

var map = createMap();

fetch('/!/nocache', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
Expand All @@ -224,6 +229,8 @@ public function getNocacheJs(): string
})
.then((response) => response.json())
.then((data) => {
map = createMap(); // Recreate map in case the DOM changed.

const regions = data.regions;
for (var key in regions) {
if (map[key]) map[key].outerHTML = regions[key];
Expand Down