Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 7415963987456321/271fc92835cacc453697fdbb31a8e9e9 to your computer and use it in GitHub Desktop.
Save 7415963987456321/271fc92835cacc453697fdbb31a8e9e9 to your computer and use it in GitHub Desktop.
Javascript refetch all imgs
// This stuff for work that I had to do at home
async function reloadImg(el) {
var elurl = el.src
await fetch(elurl, { cache: 'no-store', mode: 'no-cors' })
.then(
// Maybe append # to force cache reload
x => {
el.src = ""
el.src = elurl
}
)
};
ass = document.querySelectorAll('img').forEach(el => reloadImg(el))
//ass.forEach(e => console.log(e.src))
// Problem: the queryselector returns full-url but page has relative-url
//url = "images/food-squirts/squirting-cheese-icon.png"
//document.querySelectorAll(`img[src*='${url}']`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment