function updateImages() { for (let image of document.querySelectorAll('img')) { let url = new URL(image.src) url.searchParams.set("t", Date.now()) image.src = url.toString() } } async function submit(event) { event.preventDefault() let form = event.target let data = new FormData(form) let url = form.action let method = form.method let headers = new Headers() let resp = await fetch(url, {method, headers, body: data}) if (resp.ok) { updateImages() } else { let body = await resp.text() alert(`Error: ${resp.status} ${resp.statusText}\n\n${body}`) } } function init() { for (let f of document.querySelectorAll("form")) { f.addEventListener("submit", event => submit(event)) } } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init) } else { init() }