Prevent Caching
-
- Posts: 165
- Joined: Fri May 06, 2011 5:02 pm
Prevent Caching
How can you prevent your browser from caching a page? I think that my news feed is being cached and is causing new posts to not be displayed even after a refresh. Eventually, the posts will show up after about 20 refreshes. I know my query is right so I didn't know if there was a way to stop page caching.
Re: Prevent Caching
header("Expires: -1"); header("Cache-Control: post-check=0, pre-check=0"); header("Pragma: no-cache"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");usually you can also set the html meta tags
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" > <meta http-equiv="expires" content="0"> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache">
-
- Posts: 165
- Joined: Fri May 06, 2011 5:02 pm
Re: Prevent Caching
I'm starting to think I just have some weird bug in my code because sometimes on refresh news feed items get removed then i'll refresh again and some will get added back in then i'll refresh again and they'll all be there. Every heard of this happening?
Re: Prevent Caching
You can also make the URL random if its an ajax request.
Are you loading any of this news via ajax, I have found that javascript seems to ignore the cache control sometimes.
So make a request for news.php?random=time() or something and it would fix it.
Are you loading any of this news via ajax, I have found that javascript seems to ignore the cache control sometimes.
So make a request for news.php?random=time() or something and it would fix it.
-
- Posts: 165
- Joined: Fri May 06, 2011 5:02 pm
Re: Prevent Caching
I would love to load this via an ajax request but haven't gotten to that yet (mainly because I have no idea how to do it).jacek wrote:You can also make the URL random if its an ajax request.
Are you loading any of this news via ajax, I have found that javascript seems to ignore the cache control sometimes.
So make a request for news.php?random=time() or something and it would fix it.
I just finished the feed today... well pretty much at least. The privacy settings are in and that array merge worked perfectly for the situation.
Next for the feed will be creating the ajax pagination / more button to load then next 20 feed items and in an ideal would, just load the whole feed via ajax. Plus, it would be nice to have ajax updates.
So many things i'd love to do..... yet soo many things i'm not capable of yet
But to answer your question again, I am not using ajax to load the feed.
-
- Posts: 165
- Joined: Fri May 06, 2011 5:02 pm
Re: Prevent Caching
Caching fixed... looks like I have to close my browser and reopen it to fix the issue. Seems fine now.
Re: Prevent Caching
That's odd, but good newsunemployment wrote:Caching fixed... looks like I have to close my browser and reopen it to fix the issue. Seems fine now.