PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Jul 18, 2019 7:02 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 34 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
PostPosted: Fri Oct 07, 2016 5:55 pm 
Offline
Forum Contributor

Joined: Fri Jul 18, 2014 1:54 pm
Posts: 179
I submitted a post just before this one with the actual F12 network messages. This is my latest simple try based upon the statement that Chrome only uses this one. I am wondering if I can put it in the body the 2nd time. I am questioning whether I should bother and rather just go back to using the java script but have it bypass if it is running on the local host since I know when the data has changed and if I don't see the change I just press F5.

<html>
<head>
<meta http-equiv="cache-control" content="no-store">
</head>
<body>
lots of stuff :-)
<meta http-equiv="cache-control" content="no-store">
</body>
<head>
<meta http-equiv="cache-control" content="no-store">
</head>
</html>


Top
 Profile  
 
PostPosted: Fri Oct 07, 2016 6:13 pm 
Offline
Forum Contributor

Joined: Fri Jul 18, 2014 1:54 pm
Posts: 179
So I just did a bunch of quick writes to the static web page using notebook++ moving it up to the webhost each time. There is a pattern.
When I first change it and refresh the page I get a code 200 Okay.
From that time on I get a 304 no change.
So it is clearly checking to see if the static web page has changed at the webhost. That would be okay if it always worked but I have seen it not get the new static page changes.
I do not know how to recreate the occasional "200 (from cache)" which I get. My reading suggests this means it checked an expiry date/time and it was not expired so it used cache.
I just tried something and I finally got the "200 (from cache)" message. I closed down the browser then change the static page on the webhost but it appears to have gotten it from cache.

So after a few tests of (closing the browser down, changing the static page and moving it to the webhost, restarting the browser and calling the page) I am consistently getting 200 OK (from Cache) and it is picking up the change I made. So it is not telling the truth. it is actually getting the data from the webhost. So maybe this means (the next time it will get the page from cache if there is no change detected) rather than meaning (it actually got the data from cache which it clearly did not do).

So I just saw this "Cache-Control:max-age=0" and I did a few more tests trying to actually bump this value using meta http-equiv="cache-control" content="max-age=500" />. Google Chrome ignores this. It keeps it at zero. So it seems to want to check the file every time and if there is no change it uses cache. The problem is some times it fails (maybe once a week) and it is not smart enough to load the changed page.

So I have decided to set the javascript code back in and I sent Google a message. Hopefully they are interested enough to get back to me for more details.


Top
 Profile  
 
PostPosted: Sat Oct 08, 2016 3:04 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA
Please remove all the <meta> things you added.

I should be more specific:
1. What do the 200 and 304 responses look like when you have not updated the file? Refresh a few times and grab a copy of the headers for both types.
2. What do the 200 and 304 responses look like when you have updated the file? Refresh a few times as well.

In both cases, what "should" be happening is you get a 200 (uncached) the first time you see the file after starting the browser, then either 200 (uncached) or 304 every time after. When you update the file and keep the browser open you should get a 200 (uncached) the next time you refresh, then again a mix of 200s and 304s.

More technically,
1. You load the page, browser requests the page normally, server responds with a 200 and a Last-Modified date.
2a. You refresh, browser requests the page normally, server responds with a 200 and a Last-Modified.
2b. You refresh, browser requests the page with a If-Modified-Since header, server responds with (a) a 304 and a Last-Modified or (b) another 200 with a Last-Modified.
3. That keeps happening until you update the file.
4. You refresh and get a 200 and a Last-Modified (#1).
5. You refresh and get a 200 or 304 (#2a or #2b).

Because contrary to many popular beliefs, you should be using caching. However the type of caching in use should be using 304s: that's when the browser requests the page from the server and is told that nothing has changed from last time. A 200 "from cache" is not good because the browser is not contacting the server and thus cannot know if the file has changed; like I think you saw, that's triggered mostly by Expires, while the good caching is done using If-Modified-Since request and Last-Modified response headers.

If you're seeing a 200 "from cache" then that specifically needs to be addressed, and is likely the source of your caching problem. However without there being an Expires header in the response or one in your HTML (double-check that) then I'm not quite sure what would cause it.

(There's another way to do good caching and that's with If-None-Match/ETag headers, but they don't seem to be in use here so don't worry about them. The same basic 200/304 principles apply to those too.)


Top
 Profile  
 
PostPosted: Sat Oct 08, 2016 10:33 am 
Offline
Forum Contributor

Joined: Fri Jul 18, 2014 1:54 pm
Posts: 179


Top
 Profile  
 
PostPosted: Sat Oct 08, 2016 10:55 am 
Offline
Forum Contributor

Joined: Fri Jul 18, 2014 1:54 pm
Posts: 179
I read the rest of your response but I need to read it a few times to try and understand it fully.

So chrome seems to be simply going to the webhost computer and checking the last modified date. Based upon my tests here is the summary.
1/ Status Code:200 OK (from cache) - It gives me this when I close and open the browser again. I double checked this and it just got the actual webpage changes????
2/ Status Code:304 Not Modified - It gives me this if it detects that the file date has not been modified. I assume it is using cache and not getting the page.
3/ Status Code:200 OK - It gives me this if it detects that the file date has been modified. Obviously it is going to get the page here.
4/ Status Code:304 Not Modified - If I press F5 it must be forced to read the file again (not use cache) but it still gives this message if the file has not been modified.

The problem is real as pressing F5 proves:
Every so often chrome thinks there is no change to the file and does not display the latest updates. So I have been pressing F5 when this happens and it then gets my updated page. That is why I put in the javascript code to basically force an F5. I suspect chrome is not detecting a change in the file when I first open the browser but I am not sure. Of course when this occurs I never have the F12 developer tools network information available to me. I tried that last night and got no cigar on that idea :-)

What might be interesting to try would be to leave the javascript code out and change the pages daily hoping to see the bug again then when it finally happens instead of pressing F5 I click the refresh button instead. I can do that because the website is not actually live yet. However it might be live by the following week if I am lucky and at that point I really need to have the javascript code in so that the 21 or so other people looking at the real data do not get tripped up by this bug.


Top
 Profile  
 
PostPosted: Sat Oct 08, 2016 11:15 am 
Offline
Forum Contributor

Joined: Fri Jul 18, 2014 1:54 pm
Posts: 179


Top
 Profile  
 
PostPosted: Sat Oct 08, 2016 12:33 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA


Top
 Profile  
 
PostPosted: Sat Oct 08, 2016 3:38 pm 
Offline
Forum Contributor

Joined: Fri Jul 18, 2014 1:54 pm
Posts: 179


Top
 Profile  
 
PostPosted: Sat Oct 08, 2016 5:58 pm 
Offline
Forum Contributor

Joined: Fri Jul 18, 2014 1:54 pm
Posts: 179


Top
 Profile  
 
PostPosted: Sat Oct 08, 2016 11:35 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA


Top
 Profile  
 
PostPosted: Sun Oct 09, 2016 4:37 am 
Offline
Forum Contributor

Joined: Fri Jul 18, 2014 1:54 pm
Posts: 179


Top
 Profile  
 
PostPosted: Sun Oct 09, 2016 5:33 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6617
Location: WA, USA


Top
 Profile  
 
PostPosted: Sun Oct 09, 2016 8:49 am 
Offline
Forum Contributor

Joined: Fri Jul 18, 2014 1:54 pm
Posts: 179


Top
 Profile  
 
PostPosted: Sun Oct 09, 2016 7:41 pm 
Offline
Forum Contributor

Joined: Fri Jul 18, 2014 1:54 pm
Posts: 179
Finally I got the test to work. That is a total of 26 page changes made very quickly and all picked up by chrome. The meta code is below inserted in the main header only.

Syntax: [ Download ] [ Hide ]
<!-- 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 -->
<!-- https://developers.google.com/web/funda ... tp-caching    NOTE: this is a good tutorial -->
<!-- http://www.i18nguy.com/markup/metatags.html   NOTE: this has a good explaination of all the commands and why they are needed -->
<!-- http://www.htmlgoodies.com/beyond/refer ... he-Huh.htm NOTE: Microsoft IE only you may need to these commands again. -->
<!-- http://stackoverflow.com/questions/4954 ... l-browsers   NOTE: this gives a more complete set of commands to use -->
<meta http-equiv="cache-control" content="no-cache, public, max-age=86400">
<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 -->
 


However, I did message my webhost support asking them to check that the flags were turned on for cache control. They never got back to me to indicate they did anything so I assume they have not done anything. If that is the case then I think the order of these commands may have been incorrect.

I may run this test a few days in a row including with firefox.


Last edited by bowlesj on Mon Oct 10, 2016 5:26 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Mon Oct 10, 2016 11:56 am 
Offline
Forum Contributor

Joined: Fri Jul 18, 2014 1:54 pm
Posts: 179
For a 2nd day in a row, Chrome passed the test shown above with the meta statements shown above (another 26 tests). So I am assuming the problem is solved with Chrome. Firefox failed immediately on the first item in the list (even though I reset all the cache by going through all pages to press the refresh button) so I will be going directly to the source for the firefox as well to try and figure out why. Maybe the page below is the best one. I will look at it later.
https://developer.mozilla.org/en-US/doc ... TP/Caching


Last edited by bowlesj on Mon Oct 10, 2016 5:26 pm, edited 1 time in total.

Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 34 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


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

Jump to:  
Powered by phpBB® Forum Software © phpBB Group