Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

103
Vistas
Append cachebreaker to filenames of all images of a type

I'm able to identify all images of type (SVG) and append a cachebreaking date string in the console log.

allImg = document.querySelectorAll('img[src$=".svg"');

imgTime = Date.now();

allImg.forEach(img => console.log(img.src + '#' + imgTime));

I've been looking at this solution, but it's only for individual filenames, not multiple images: https://stackoverflow.com/a/1077051/3787666

Any help appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Okay, here's how it works, adding a cachebreaker to every SVG image in a page:

allImg = document.querySelectorAll('img[src$=".svg"');

imgTime = Date.now();

allImg.forEach(img => {
    //console.log(img.src);
  newImgSrc = img.src + '?' + imgTime;
    //console.log(newImgSrc);
  img.src = newImgSrc;
});

Caveat is that this forces the SVGs to load a second time, so, if it's feasible to write the cachebuster into the original IMG SRC, that would generally be preferable. The site constraints in this particular use case mean that's not an option.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda