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

341
Visualizações
Auto-Versioning inline Javascript in a PHP File?

I have the following question / problem: I know that if I append something like "?v=*" in my Javascript includes such as <script src="/js/myJsFile1.js?v=1.1" type="text/javascript"></script> I can force a client side recaching.

Now my question is, if I have a fragment such as the following in an example.php...

<?php ... ?> 
<script> 
    var a = 5; 
    callRandomFunction(); 
</script> 

...is there a need to have a version-control for this fragment as well? As it is included in a PHP File and therefore always called from the server anyway, does a forced caching make sense here?
If it does - Is there some similar way as there is with the "?v=" appendix?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

A few points of confusion:

  • "caching" refers to re-using content; the techniques you are talking about are not "forced caching", they are forcing the browser not to use a cached copy
  • the parameter doesn't mean anything to the browser, it just means that this is a URL the browser has never seen before, so it won't have a cached copy
  • the browser doesn't see that something is part of a PHP page, only that it's part of an HTML page
  • the browser doesn't cache parts of pages, so if that HTML page is cached, the JS inside the page is cached too; if it is not, it is not
    • to be clear, JS served on a separate URL but referenced in the HTML page will be cached separately, which is why changing the URL for each version makes a difference

So, the question comes down to:

Will my HTML page be cached?

The answer depends on cache headers, which are a surprisingly complicated part of HTTP. But the short version is that PHP will generally set headers telling the browser not to cache pages it generates.

So the really short answer is: no, you don't need to do anything.

about 4 years ago · Juan Pablo Isaza Relatório
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