How to disable Godaddy server cache?

Asked

Viewed 522 times

2

I’m having a problem with server caching on Godaddy. I don’t know if this is with all Godaddy clients with a shared server or just my account.

I happen to make changes to a file and upload, but the change is not reflected until a few minutes. This makes programming impossible.

I searched and found some information about APC in php.ini, but I don’t have access to that file in my account.

Is there any way to change that?

  • Will be of this you’re looking for?

2 answers

4

Did you mention the php.ini in your question even though you didn’t use the tag PHP.

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...
?>

This way will always be served a new copy of your page in each access!


Learn more about the function header() of PHP English

header() is used to send a raw HTTP header. See the »HTTP/1.1 Specification for more information on HTTP headers.

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

That translated:

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

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

1

With .htaccess (which is recommended)

First of all, create a file called .htaccess and send 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>

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 above example, 5 days of caching was given. See below for other examples.

Before you go on 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 code above replace: "max-age=432000 for "max-age=172800 and your cache will last 2 days.


Disabling the Cache

To disable the cache just replace in the first mentioned code "max-age=432000 for "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>

Observing: i configured the above code only for files .css and .js (which is what is usually kept as cache),

If you want to add more extensions, like images, etc....

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

<FilesMatch "(css|js)$">

To add images the cache settings just leave it so:

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

You should separate the extensions with |.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.