Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    851
    Thanks
    172
    Thanked 93 Times in 93 Posts

    set expire header

    Hi all

    Yeh, I'm pretty sure this is easy for everyone here but it's new to me.

    I have this notice from my page and I want to follow the instruction

    "The following cacheable resources have a short freshness lifetime.
    Specify an expiration at least one week in the future for the following resources:"

    mysite.com/css/placement.css
    mysite.com/css/topmenu.css
    mysite.com/css/example.css
    mysite.com/images/img1.jpg
    mysite.com/images/img2.jpg
    mysite.com/images/img3.jpg
    //
    etc it lists all the images on the page

    I'm not sure what is the best / correct way to do this

    Do I have to set the expire header like this at the top of my page
    and change it on a weekly basis? (can't be right)

    PHP Code:
    header('Expires: Fri, 01 Jan 2012 05:00:00 GMT'); 
    Help much appreciated

    LT
    "The greatest revenge is to accomplish what others say you cannot do."
    ~ Unknown

    I used to be indecisive, but now I'm not so sure.

  • #2
    12k
    12k is offline
    New Coder
    Join Date
    Jan 2012
    Posts
    29
    Thanks
    0
    Thanked 6 Times in 6 Posts
    You should just use a htaccess file.

    Examples:
    http://www.askapache.com/htaccess/ap...e-control.html

  • Users who have thanked 12k for this post:

    low tech (01-22-2012)

  • #3
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    851
    Thanks
    172
    Thanked 93 Times in 93 Posts
    Hi

    Thanks for the link

    I'm still in need of help so if anybody can throw more light on this subject that would be appreciated.

    After a lot of reading i'm still pretty clueless.

    Does this look right? What should I set the Expire Year to? One year from now ie 2013 so it will cache -- is that right?

    What happens if page content eventually changes --- which it will --- I can't rename the page because it's an index page --- how does the Last_Modified header work?

    Like I said -- still pretty clueless:-(


    <filesMatch "\.(ico|jpg|jpeg|png|gif|js|css)$">
    Header set Cache-Control "public"
    Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
    </filesMatch>

    # 2 HOURS
    <filesMatch "\.(php|html|htm)$">
    Header set Cache-Control "max-age=7200, must-revalidate"
    </filesMatch>



    LT
    "The greatest revenge is to accomplish what others say you cannot do."
    ~ Unknown

    I used to be indecisive, but now I'm not so sure.

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,625
    Thanks
    0
    Thanked 645 Times in 635 Posts
    One thing to note is that if your site is using shared hosting then the hosting provider is not going to allow you to adjust the expires header - they will have set it to a fixed value for the entire server so as to provide the most efficient setup for the typical sites that they host.

    You will only have access to set it if you have VPS or dedicated hosting. In that case you are probably best off setting it up in the appropriate Apache configuration files so as to not need to override the values in individual .htaccess files all over the place.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    low tech (01-22-2012)

  • #5
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    851
    Thanks
    172
    Thanked 93 Times in 93 Posts
    Hi felgal

    One thing to note is that if your site is using shared hosting then the hosting provider is not going to allow you to adjust the expires header
    Fantastic info ----- yep i'm on shared hosting. Never knew about that and nothing I read even remotely mentioned that.

    So I guess I should just leave it as is and not mess with anything.

    I think i'll ask my hosting provider about expire headers anyway just to find out for myself what they have to say on it.

    Using Firefox I can see this as my response headers and there is no mention of Expires, Cache-Control or Last-Modified ---- non of which I understand anyway but I thought these should be set.

    Date: Sun, 22 Jan 2012 00:57:40 GMT
    Server: Apache
    X-Powered-By: PHP/5.2.17
    Content-Length: 49557
    Connection: close
    Content-Type: text/html

    200 OK

    anyway

    thanks
    very helpful

    LT
    "The greatest revenge is to accomplish what others say you cannot do."
    ~ Unknown

    I used to be indecisive, but now I'm not so sure.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •