www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: What's the best way to force a browser NOT to cache a page?

  1. #1
    Join Date
    Sep 2003
    Posts
    218

    What's the best way to force a browser NOT to cache a page?

    Can someone tell me what's the best way to force a browser NOT to cache a page?

    And would any such method work on 95% of browsers?
    (If so... I'd be more than happy!)

    Any help would be appreciated.

    Thanks.


    Jam

  2. #2
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,222
    none. You can't force a browser ot do anything like that really. You can add a header or use a meta tag to tell the browser not to read from cache when it comes back, but there is no way to tell it not to cache the content, no-cache and all will not do it.

  3. #3
    Join Date
    Nov 2002
    Location
    Nashua, NH
    Posts
    3,195
    The following headers do the job on most occasions:
    PHP Code:
    header("Content-type: text/javascript");
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
    header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT"); 
    header("Cache-Control: no-store, no-cache, must-revalidate"); 
    header("Cache-Control: post-check=0, pre-check=0"false); 
    header("Pragma: no-cache"); 
    Vladdy

    Working web site is not the one that looks the same in a few graphical browsers, but the one that adequately delivers its content to any device accessing it.

  4. #4
    Join Date
    Oct 2003
    Location
    The Dryer
    Posts
    538
    Originally posted by Vladdy
    The following headers do the job on most occasions:
    PHP Code:
    header("Content-type: text/javascript");
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
    header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT"); 
    header("Cache-Control: no-store, no-cache, must-revalidate"); 
    header("Cache-Control: post-check=0, pre-check=0"false); 
    header("Pragma: no-cache"); 
    And just so you know, jammer, that is php. And if you use it, you have to rename your file as whatever.php and those lines of code have be at the very top of your .php file inside of <?php ?> tags

  5. #5
    Join Date
    Oct 2003
    Location
    The Dryer
    Posts
    538
    PHP Code:
    header("Content-type: text/javascript"); 
    whats the point of that one?

  6. #6
    Join Date
    Sep 2003
    Posts
    218
    Thanks for all the replies.
    How can I put the above code straight into HTML?
    Let me know.
    Thanks.

  7. #7
    Join Date
    Nov 2002
    Location
    Nashua, NH
    Posts
    3,195
    Originally posted by The Cheat
    whats the point of that one?
    oops, I was copying it from a file returning javasript. Do not need that one for caching.....
    Vladdy

    Working web site is not the one that looks the same in a few graphical browsers, but the one that adequately delivers its content to any device accessing it.

  8. #8
    Join Date
    Jan 2004
    Location
    Alabama, United States
    Posts
    833
    Why are you wanting a 'no-cache' solution?? If it's an attempt to keep your source/images/whatever from being stolen then you need to give up now. All a no-cache does is tell the browser to ignore what it has downloaded on a previous visit and use a fresh copy of what's on the server; it DOES NOT keep the browser from dowloading content. source/images/whatever HAVE to be downloaded; it's the only way the browser can show the page.

  9. #9
    Join Date
    Sep 2003
    Posts
    218
    Erm... well the problem is that I'm having trouble with my Flash files.

    What 'normally' work is if I change the name of the Flash file and make these changes in the HTML.

    When the HTML page is loaded, the new Flash movie is loaded and not the old one.

    But for some reason... when I'm making the changes to my HTML... the old page is being picked up - despite repeatedly refreshing AND going to 'internet options' and deleting stored files.

    Could it be that my ISP is causing the problem by caching on their servers?

    Whatever... surely... if I can figure out how to stop the browser caching... then this would solve my problems?

    Let me know what you think.

    Thanks.


    Jam

  10. #10
    Join Date
    Nov 2002
    Location
    Auburn, AL
    Posts
    9,222
    Originally posted by Vladdy
    The following headers do the job on most occasions:
    PHP Code:
    header("Content-type: text/javascript");
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
    header("Last-Modified: " gmdate("D, d M Y H:i:s") . " GMT"); 
    header("Cache-Control: no-store, no-cache, must-revalidate"); 
    header("Cache-Control: post-check=0, pre-check=0"false); 
    header("Pragma: no-cache"); 
    I thought that just told the browser to recache it, i thought thats how the browser took it, whenever it visits it does not read from cache. Because I recall being able to look at sites with headers like that and the meta tags while off line. For these purposes it will make the browser use a fresh copy, but saying it does not cache it is not technically correct I believe... or atleast not with my browser.

  11. #11
    Join Date
    Nov 2003
    Location
    Jerryville, Tejas
    Posts
    11,715
    Originally posted by jammer20002
    Thanks for all the replies.
    How can I put the above code straight into HTML?
    Let me know.
    Thanks.
    Those are HTTP headers so to put them literally into the HTML you would use the <meta http-equiv="" content=""> tag.

    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); becomes
    <meta http-equiv="Expires" content="Mon, 26 Jul 1997 05:00:00 GMT">

    header("Cache-Control: no-cache"); becomes
    <meta http-equiv="Cache-Control" content="no-cache">

    header("Pragma: no-cache"); becomes
    <meta http-equiv="Pragma" content="no-cache">

  12. #12
    Join Date
    Sep 2003
    Posts
    218

    Thumbs up

    Thanks for all the replies.

  13. #13
    Join Date
    Apr 2004
    Posts
    32
    For Internet Explorer you can hold down the control key and hit the refresh button or cntrl-F5. F5 is the hot key to refresh the browser. I believe its Shift-Refresh for Netscape and Mozilla variants. This will tell the browser not to load from cache but go get the new page off the server.

  14. #14
    Join Date
    Sep 2003
    Posts
    218
    Originally posted by KarmaKills
    For Internet Explorer you can hold down the control key and hit the refresh button or cntrl-F5. F5 is the hot key to refresh the browser. I believe its Shift-Refresh for Netscape and Mozilla variants. This will tell the browser not to load from cache but go get the new page off the server.
    Well, that was one of the problems. I was doing this a million times - and it still didn't work!

    I then tried to delete all the temporary files stored - that didn't work either.

    Any suggestions/exaplantions of why the above occured?

    I'm not sure that the above code will work to solve the above problem, but I do need it for all the other work I do.

  15. #15
    Join Date
    Oct 2003
    Location
    The Dryer
    Posts
    538
    i've heard of this a lot from people who make flash movies. I think the secret is to close the browser and reopen

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles