Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
Is there an official way to avoid cache for some img image elements?

This has been discussed here and there. I'd made my own solution but I'm wondering if there is some modern official solution by newer standard as ECMAScript 2016.

My solution is a hack in the src property adding a random fake property in the end:

function xhrUrlHackNoCache(first) {
    var hack = (first)? "?nocache=" : "&nocache=" ;
    for(let i=0; i<5; i++) {
        hack += Math.floor(Math.random()*10).toString();
    }
    return hack;
}

Personally, I think this is ugly...

There is some interesting discussion here. Some I already tested and won't work as header definition, not even when loading the image trough a php script (maybe if I load the image as 64 and create the img object). Maybe manipulating .htaccess file, but I don't have much knowledge about (sometimes I drop my website messing with this file).

The heaven to me will be some img property set to avoid the cache and load this imagem from the file. Is there something like this? What's the best practice in this case today?

If there is nothing new to add to this issue (that has a lot of duplicates) than I might delete it, no problem, but I think is a good idea to update the knowledge about it.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda