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

252
Visualizações
How can I use Cache-Control in Javascript?

I want to use Javascript to tell the browser not to cache my site. The code written on this JavaScript file is as simple as

function calcURL(urlIn)
{
    Cache-Control: no-cache, max-age='3600'
}

The browser keeps giving me an error:

Uncaught SyntaxError: Unexpected token ':'

I have tried adding ; at the end of the line. Can someone tell me what the problem is?

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

0

You have used wrong method in JavaScript. Also it will be too late until JS run to tell browser not to cache .

You can read this for more about cache control

Cache-Control configuration

The HTTP Cache-Control header can be implemented on the server or can even be added within the code. The following are examples of how to implement Cache-Control in Apache, Nginx, or within your PHP code.

Apache

The following snippet can be added to your .htaccess file to tell the server to set the Cache-Control header's max-age to 84600 seconds and to public for the listed files. Expires and Cache-Control headers can also be included with Apache by using the mod_expires module.

<filesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
    Header set Cache-Control "max-age=84600, public"
</filesMatch>

Nginx

This snippet can be added to your Nginx configuration file. The example below uses the Cache-Control header directives public and no-transform with an expire setting set to 2 days.

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires 2d;
    add_header Cache-Control "public, no-transform";
}

PHP

Cache-Control headers can also be added directly in your code. This example demonstrates using the PHP header to include Cache-Control setting a max-age of 1 day.

header('Cache-Control: max-age=86400');

Summary
Cache-Control is a powerful HTTP header when it comes to speeding up websites with the use of browser and intermediary cache. Although its ability to increase website speed is not it's only as it is also quite useful to help make private information less vulnerable. The settings you choose to apply to the Cache-Control directives are dependent on the nature of information that is being delivered as well the desired expiration time of those assets.

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