Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Cache-Control doesn't seem to work. Any ideas?


  • Please log in to reply
1 reply to this topic

#1 webrat

webrat

  • Members
  • 138 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:UK
  • Local time:02:36 PM

Posted 29 January 2015 - 07:33 PM

Hi folks,

 

I've been trying to implement Cache-Control mainly because it's good practice but also because I'm trying to improve my understanding of it. The code I'm using in my htaccess is this:

<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"
</IfModule>

which I found on my hosts support pages as their suggested way to do things. After implementing it I ran a pagespeed test and this tells me I'm not caching content and the headers, which I checked with another tool reflected this, showing no-cache. At this point I did some further research on the code itself and it seems legit and should in theory work. Does anyone have any ideas why it's not being picked up? 

 



BC AdBot (Login to Remove)

 


#2 webrat

webrat
  • Topic Starter

  • Members
  • 138 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:UK
  • Local time:02:36 PM

Posted 04 February 2015 - 12:42 PM

In case others might find it useful I did more research and the following works as intended. It caches for the end user but not proxy servers. You can adjust the cache time according to need.

# Set Cache-Control and Expires headers
<filesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$">
Header set Cache-Control "max-age=2592000, private"
Header set Expires "Sun, 17 July 2011 20:00:00 GMT"
</filesMatch>
<filesMatch "\\.(css|css.gz)$">
Header set Cache-Control "max-age=604800, private"
</filesMatch>
<filesMatch "\\.(js|js.gz)$">
Header set Cache-Control "max-age=604800, private"
</filesMatch>
<filesMatch "\\.(xml|txt)$">
Header set Cache-Control "max-age=216000, private, must-revalidate"
</filesMatch>
<filesMatch "\\.(html|htm)$">
Header set Cache-Control "max-age=7200, private, must-revalidate"
</filesMatch>






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users