Hi, This code does not work consistently. Some background is in order on this one. I am running my website on my local host using xampp then I pull up pages and save them to my downloads directory using google chrome and then move them up to the web hosting directory. I am doing this because there is no money being made and at present things are really simple so I don't want a VPS at the webs hosting company. So I discovered that often the updates were not getting picked up because google chrome puts things in cache memory. This was happening both on the local host and on the webhost. So at first I put a comment on the pages telling the 20 people using these static pages to press F5. Then I realized there should be a way to automate it. I found the javascript below. It worked except I wanted to avoid the double running of the code if possible (avoid the screen flash too). So I asked on another forum that is part of my program that gives me WYSIWYG assistance and the main owner of that company suggested the html code below. It did not work at all from what I could tell. So I put the javascript code back in. Then I noticed with the debugger last night that the javascript code reruns the php code every single time without fail (runs it twice). So then I put in the local host test in to bypass the 2nd run if the local host was producing the pages and at first that seemed to fix the problem (the static pages did run the javascript code to ensure the users got the latest data but the xampp local host code did not run the php twice but did at least run it once). So this morning I found that this failed and the updates were not showing. So I decided to comment the localhost test out of the javascript and let it force the php to run twice to be sure the updates are reflected on the page every time. However this seems kind of dump to me. Surely there must be a proper solutions that forces google chrome to never store a specific page in cache memory such that the page does the php run but only once. Maybe someone has struggled with this before and found a solution that actually works (a solution that is 100% guaranteed to shut off the caching of a page forcing the localhost php code to build the page once only every time or causing the static pages to always be picked up from the webhost computer).

<!-- START: HTML code to make sure your page is not stored in cache so that you do not need to tell them to use F5 --><meta http-equiv="cache-control" content="max-age=0"/><meta http-equiv="cache-control" content="no-cache"/><meta http-equiv="expires" content="0"/><meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT"/><meta http-equiv="pragma" content="no-cache"/><!--END: HTML code to make sure your page is not stored in cache so that you do not need to tell them to use F5 -->

//START: code to bypass the F5 refresh if we are working from the local host. The static pages still do an F5 refresh// IMPORTANT: It seems that you still have to force this even if you are on the local host. What good is that because most times everything runs twice.//var MyHost = window.location.hostname;//var MyPath = window.location.pathname;//if(MyHost == 'localhost') {// return true;//}//END: code to bypass the F5 refresh if we are working from the local host. The static pages still do an F5 refresh

//START: code to force an F5 refresh
$(document).ready(function(){//Check if the current URL contains '#'if(document.URL.indexOf("#")==-1){// Set the URL to whatever it was plus "#".
url = document.URL+"#";
location ="#";

//Reload the page
location.reload(true);}});//END: code to force an F5 refresh

}</script>

<noscript><p>
This website will not run properly without javascript enabled. Please enable javascript and try again.<br>
This website will not run properly without javascript enabled. Please enable javascript and try again.<br>
This website will not run properly without javascript enabled. Please enable javascript and try again.<br>
This website will not run properly without javascript enabled. Please enable javascript and try again.<br>
This website will not run properly without javascript enabled. Please enable javascript and try again.<br>
This website will not run properly without javascript enabled. Please enable javascript and try again.<br>
This website will not run properly without javascript enabled. Please enable javascript and try again.<br>
This website will not run properly without javascript enabled. Please enable javascript and try again.<br></p></noscript>

It sounds like you're saying that1. You're writing stuff involving PHP code.2. When you're satisfied with your stuff, you use Chrome to save the page as displayed by XAMPP, then upload that file you just "downloaded" to your host?

Regarding what I am doing, I get an email from a very small number of people to do an update on my local host, I do the update on my localhost, I display the pages I want to show on the webhosting site, I save them in google chrome by doing this (right click, save as, webpage complete), then I put the pages on the webhost machine where they can see the updates. If I get too busy and I start making enough money to pay for the VPS then I put the software on a VPS and I have them do the updates.

Regarding the question I have, I came up with a simple google search "how to stop web page caching". If found the page below.http://www.htmlgoodies.com/beyond/refer ... he-Huh.htmHe mentioned two of the commands I was using the first time around and explained why they do not work.He seems to have researched it fairly well so I am going to try this for a few days to see if it ever fails.

I also found the chrome://cache/ command to see what pages are in google chrome cache and I found this webpage which explains how to clear cache without clearing other stuff.http://superuser.com/questions/278948/c ... -in-chromeBy doing this I can more quickly determine if the change worked rather than waiting a few days.

Also this worked well to clear the cache of the pages for my webiste so I can see if they are getting in cache now by using the above mentioned chrome://cache/ commandHttp://superuser.com/questions/278948/c ... -in-chromeOpen up a page on the website you want to clear the pages for.in google chrome just left of the URL box click on the "reload page" button but hold it until you see a little menu of three or so items.From the popup list, choose "Empty Cache and Hard Reload".Not sure this clears the cache for the entire domain. But probably satisfies 90% of the use cases of people that visit this SE question.Note: In some cases this will NOT open the popup list. This is because the page isn't cached at that time, so the menu is not invoked.

These instructions from Google actually worked for clearing the pages from google chrome cache so I can test the new html code:Open Chrome.On your browser toolbar, click More More.Point to More tools, and then click Clear browsing data.In the "Clear browsing data" box, click the checkboxes for Cookies and other site and plug-in data and Cached images and files.Use the menu at the top to select the amount of data that you want to delete. Choose beginning of time to delete everything.Click Clear browsing data.

Yes, I am using PHP to generate the page. The PHP code is well tested and working. No problems there. I use netbeans to make sure it is working properly.

I am not good at short answers...lol. Typical programmer

My latest and greatest attempt to keep the page from every being displayed from cache memory is below. I have it twice (once between the <head></head> tags and once at the end of the page as per the first website suggestion). I am trying to figure out a fast way of knowing for sure if the page is in cache memory after it has been displayed on the screen. I have just now been using the chrome developer tools (F12) network to try and figure it out. On that developer tool if I click "disable cache" it appears to not be using cache. But if that checkbox is not pressed and I start fresh to load the page I get this: "Status Code:200 OK (from cache)". So maybe that means the code below is not actually working????

<!-- START: HTML code to make sure your page is not stored in cache so that you do not need to tell them to use F5 --><!-- http://www.htmlgoodies.com/beyond/refer ... he-Huh.htm --><!-- http://stackoverflow.com/questions/4954 ... l-browsers --><HEAD><meta http-equiv="cache-control" content="max-age=0"/><meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate"/><meta http-equiv="expires" content="-1"/><meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT"/><meta http-equiv="pragma" content="no-cache"/></HEAD><!--END: HTML code to make sure your page is not stored in cache so that you do not need to tell them to use F5 -->

The problem has nothing to do with Chrome. It has nothing to do with caching. Congratulations on becoming familiar with a subject that is often an issue for people, but this time it is not to blame.

When you wrote your code you put it into a .php file and accessed it through your browser at http://localhost/file.php or something similar. Apache receives the request, tells PHP to execute that file, and the output gets sent back to your browser. You don't see the code itself but the result of the code executing. The HTML it generated and whatever.

When you saved in Chrome, you saved that result. You saved a copy of the page that PHP generated that one time you accessed it. You don't get any of the code that was involved in the process.

Take a look for yourself: compare that file you saved with the stuff you wrote. None of the PHP code will be there.

You have to upload the original file. What you wrote. And you need a host that supports PHP but I can only assume yours does that (or else you wouldn't be using them). That way when people access the page the PHP runs for itself and does whatever it needs to do.

While you're in there, remove all the caching stuff you've added. You very likely don't need it, and in fact it could be harmful.

I think maybe I found the problem. The code above (which was suggested by the earlier mentioned google search link) I had incorrectly placed below the </HTML> tag rather than just above it. So the way I know it appears to be working is now when I load the page fresh while using the chrome developer tools is I no longer get "Status Code:200 OK (from cache)" but rather I get "Status Code:200 OK". This is the same message I get if I check the checkbox in the developer tools to disable the cache.

Yes, I understand what you are saying totally except what you are saying in the quote below is wrong.

Quote:

You have to upload the original file. What you wrote. And you need a host that supports PHP but I can only assume yours does that (or else you wouldn't be using them). That way when people access the page the PHP runs for itself and does whatever it needs to do.

Just to let you know that I know what I am talking about here, Again, I run xampp on my local host which processes the php code and ships the html code and the javascript up to the browser on my local host and it displays it. I often right click on the resulting page and click "view page source" and as you say I see the html code without any of the php code that is generating it. Okays so try this yourself. Generate a page on your local host and right click on the page and instead of clicking "view source" instead click "save as" then save it to some work area on your C drive. Then go to that place and double click on the file name you just saved and it will display the static page. It works fine. I then ship this static page up to the webhosting machine and it works fine. I have friends who view it from their computers in a different city and they tell me it looks fine.

I had a VPS about two years ago and I was running php code on the webhosting service. It was costing me $20.00 a month. By doing it this way using static web pages (a much simpler website) I only need to pay $4.00 a month. Again, once my project proves itself and I get more than 20 people sending me requests to update the file then I will do what you are saying by putting my php code on the VPS service at the webhosting company and off load the work to them with a login process.

I just tried again and I still get that message "Status Code:200 OK (from cache)" so I guess it is still reloading my page from cache?

Last edited by bowlesj on Fri Oct 07, 2016 2:44 pm, edited 2 times in total.

So you're only using PHP to, like, generate the page you want to show? You don't need PHP actually running on the live site, just static HTML and CSS/Javascript?

Yes that is exactly correct.

Ironically by doing it with static pages I was much more likely to learn about this cache issue because I know what the webhosting page was displaying before and I know what the updated page is suppose to look like and I realize that my updates are not showing then once I press F5 my updates do show. In other words, it slowed the whole process down enough that I caught on.

Anyway, I updated my prior post. I am not sure if I have solved it. The guy in this link seems to really know a lot about the caching issue. http://stackoverflow.com/questions/4954 ... l-browsersHe seems to know how these header commands are processed in great detail. I read that the order is important. Maybe I have them sequenced incorrectly. But like I say, I am not sure. Maybe it is working.

UPDATE: I think I have some of the code positioned incorrectly relative to the <html> commands and also incorrectly relative to the <head> commands too. Fixing it right now.

If you think you have everything set up right but it's still not working, then

You should try to identify the exact source of the problem before embarking on a mission to try to fix everything that could possibly be at fault.Can you reproduce the issue yourself? Can you verify that the browser is not, in fact, re-requesting the page every time? (Inspector thing, Network tab, load page, and the request should say 200 without being served from the cache)

The list is just examples of different techniques, it's not for direct insertion. If copied, the second would overwrite the first and the fourth would overwrite the third because of the http-equiv declarations AND fail with the W3C validator. At most, one could have one of each http-equiv declarations; pragma, cache-control and expires.

So after reading a bit of them all (as a simplification) it appears that I should just try "no-store" since apparently Chrome only needs this (I think....lol).

That problem is I can't figure out how to confirm it. The F12 thing and the chrome://Cache command both say it is not working.

Now the other day while performing a site performance audit I noticed that a lot of our assets were returning 304 statuses. While comparing another site I noticed that it was returning a 200 (from cache) status code. This intrigued me and I wanted to dig deeper.

It turns out that when a 200 (from cache) response is given it means that a future expiration date on the content is set. In essence the browser doesn’t even really communicate with the server to check on the file. It knows not to do it until the expiration date has expired.

By contrast a 304 goes to the server and receives a response back that the data has not change. The server is telling the browser to use the cache as a result.

Caching is very easy to address if you can determine the exact problem. Stop taking the shotgun approach and throwing all sorts of markup at it, hoping that one of them will make the problem go away, and determine precisely what is going on.

How is the browser requesting the page? 200? From cache? 304? What are the actual response headers from the server?

Regarding your question, I am assuming you mean "can you see the actual meta command I am sending when I view the F12 network info". That is the problem. I am not sure if my meta commands are being used since I see no reference to them. This is one of my last ones. I assume it means it got the data from cache which is what I don't want.

Who is online

Users browsing this forum: No registered users and 4 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum