How to disable Godaddy server cache?

2

I have a problem with server caching on Godaddy. I do not know if this is with all Godaddy clients with shared server or just with my account.

It turns out that I make changes to a file and upload it, but the change is only reflected after a few minutes. This makes programming impossible.

I searched and found some information about APC in php.ini, but I do not have access to this file in my account.

Is there any way to change this?

    
asked by anonymous 23.05.2014 / 06:05

2 answers

4

You referred to php.ini in your question even though you did not use the PHP tag.

In case you are using PHP, there are headers to instruct browsers and proxy servers that should not cache your page:

<?php

// define data de expiração da página no passado
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");

// define a data de ultima actualização para "agora"
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

// indica aos navegadores e proxies para não fazerem cache da página
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

// teu código depois dos headers...
?>

In this way, a new copy of your page will always be served at each access!

Learn more about header() PHP English

  

header () is used to send a HTTP header. See HTTP / 1.1 specification for more information on HTTP headers.

     

Remember that header () should be called before any current output is sent, either by normal HTML tags, blank lines in a file, or from PHP.

What translated:

  

header () is used to send a raw HTTP header. See »HTTP / 1.1 specification for more information about HTTP headers.

     

Remember that header () must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.

    
09.07.2014 / 23:48
1

With .htaccess (which is recommended)

  

First of all, create a file named .htaccess and send it to the root of your site (public_html).

Control the Cache

Inside the file insert the following code:

#5 dias de cache
# O cabeçalho "pragma" é para compatibilidade com o IE
<FilesMatch "(css|js)$">
Header set Cache-Control "max-age=432000, public, must-revalidate"
Header set Pragma "max-age=432000, public, must-revalidate"
</FilesMatch>
  

In this way when a person accesses your site, the cache will be stored for 5 days, after 5 days, if the person accesses again, the cache will be updated, that is, a new version of your cache will be downloaded.

In the example above, 5 days of cache was given. See below for other examples.

Before proceeding know, um dia tem 86.400 segundos .

That is, if you want the cache to last only 2 days, multiply 2x 86400 seconds which is equal to: 172800 seconds.

Then in the above code replace: "max-age=432000 with "max-age=172800 and your cache will last 2 days.

Disabling the Cache

  

To disable the cache, just replace it in the first code quoted "max-age=432000 with "max-age=0 this way you will have your cache disabled.

The final example will be:

#Sem cache
# O cabeçalho "pragma" é para compatibilidade com o IE
<FilesMatch "(css|js)$">
Header set Cache-Control "max-age=0, public, must-revalidate"
Header set Pragma "max-age=0, public, must-revalidate"
</FilesMatch>

Note: I have set up in the above code only for files .css and .js (which is what is usually kept as a cache)

If you want to add more extensions, such as images , etc ...

Just add in the above code the desired extension, more precisely in:

<FilesMatch "(css|js)$">

To add images to the cache settings just leave it like this:

<FilesMatch "(css|js|png|jpeg|ico|gif)$">

You should separate the extensions with | .

    
10.07.2014 / 01:20