Use XHR to load HTML templates

This commit is contained in:
Cohee 2024-01-12 22:00:08 +02:00
parent 4fe13fab8e
commit 6086cedf2b
1 changed files with 16 additions and 7 deletions

View File

@ -533,13 +533,22 @@ $(document).ajaxError(function myErrorHandler(_, xhr) {
} }
}); });
function getUrlSync(url, cache = true) { /**
return $.ajax({ * Loads a URL content using XMLHttpRequest synchronously.
type: 'GET', * @param {string} url URL to load synchronously
url: url, * @returns {string} Response text
cache: cache, */
async: false, function getUrlSync(url) {
}).responseText; console.debug('Loading URL synchronously', url);
const request = new XMLHttpRequest();
request.open('GET', url, false); // `false` makes the request synchronous
request.send();
if (request.status >= 200 && request.status < 300) {
return request.responseText;
}
throw new Error(`Error loading ${url}: ${request.status} ${request.statusText}`);
} }
const templateCache = new Map(); const templateCache = new Map();