8

I have a php site using html5 run on a linux server on godaddy. I need to set a cache expiration date on static images and a css file. I also need to gzip a css file and cannot seem to find the correct syntax for either. I am not sure if I am making this too complicated or what. Am I correct to think I can get this done with an expire header in the top of my php pages? I feel lost and I know what i am doing! I do not have control over the server.

Johan
  • 71,222
  • 23
  • 174
  • 298
Joe R
  • 89
  • 1
  • 1
  • 3
  • Do you have access to your apache/php configuration file? can you use .htaccess files to control your apache settings? – AlfaTeK Jan 19 '10 at 22:37
  • I have access to my php config file. YES, I can use htaccess to control apache settings. However htaccess is in my wordpress dir not my root. – Joe R Jan 20 '10 at 01:29

5 Answers5

3

This is definitely possible if you have control over the server, and maybe possible through .htaccess if you're on shared hosting.

Try these SO questions:

Community
  • 1
  • 1
Pekka
  • 418,526
  • 129
  • 929
  • 1,058
2

Godaddy can be extremely frustrating. I have been seeking a means of using expires header with Godaddy hosting for some time and haven't found a solution yet.

I have the following in htaccess ('A2592000' indicates 1 month) and it works with other hosts but not Godaddy :(

ExpiresActive On
ExpiresDefault A0
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/ico A2592000
ExpiresByType text/css A2592000
ExpiresByType text/javascript A2592000
Gary
  • 21
  • 1
1

I had completely same problem. Disaster with GoDaddy. Never more their hosting :(

But I found solution: https://support.godaddy.com/help/article/6908/enabling-mod_expires-with-your-hosting-account?locale=en

I do not know how you manage your hosting but I use FileZila to connect to FTP. So after I connect to FTP you can rewrite .htaccess file :) so download original one and add this code after:

<IfModule mod_expires.c>
# Activate mod_expires for this directory
ExpiresActive on

# locally cache common image types for 7 days
ExpiresByType image/jpg "access plus 7 days"
ExpiresByType image/jpeg "access plus 7 days"
ExpiresByType image/gif "access plus 7 days"
ExpiresByType image/png "access plus 7 days"

# cache CSS files for 24 hours
ExpiresByType text/css "access plus 24 hours"

I hope this will help you. (it helped me:D)

0

You can try this

<FilesMatch "\.(jpg|png|gif)$">
ExpiresDefault A0
Header set Cache-Control "max-age=0,  no-cache, must-revalidate"
</FilesMatch> 

Which mean, that expiration date is in access moment and set headers to 0 values.

As You can see, here You can add more filetypes

/via http://blog.simplemediacode.com/cache-expiration-on-static-images-and-content-with-htaccess/

Can Poyrazoğlu
  • 29,145
  • 40
  • 152
  • 327
0

You're looking for something like this:

Header set Cache-Control "max-age=2678400"

Where max-age is set in seconds.

Additional, if your contents is still not being cached, read my post at Why isn't my javascript & css caching? for additional cache-config-magic.

Community
  • 1
  • 1