The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> How to defeat page caching
DDD
post Aug 12 2022, 12:54 PM
Post #1





Group: Members
Posts: 7
Joined: 12-August 22
Member No.: 28,503



Hi... I'm new to this forum. I have a problem with page caching.We have a cafe and we publish an online menu every week. We also make frequent changes to the menu throughout the week. The problem is that customers see the previous version of the menu and order from it because the page loads on their devices from a cache. I have tried everything I can find (META data, script, etc.) to force the page to reload every time but nothing seems to fix the problem.

If you look at the page...

http://www.farmerskitchencafe.com/submeals/menu_form.html

...you can see that I have added a reload button and that works but customers still miss it and end up ordering from the wrong menu.

So, I am wondering if, since the button works to reload the page, if there is any way to, in effect, automatically press the button when the url is hit. I only want the page to reload when they hit it because if there is a timeout on it, it may reload before they have a chance to fill out and submit the form.

Thanx in advance for any insight you can provide. I might add that I am not a "coder". I use Adobe Dreamweaver to make the pages.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Aug 12 2022, 01:20 PM
Post #2


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



This can be done with HTTP headers, for example, by this PHP script at the very top of the HTML file (before everything else, including any whitespace):

CODE
<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>


See also
https://www.php.net/manual/en/function.header
https://www.mnot.net/cache_docs/

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
DDD
post Aug 12 2022, 01:42 PM
Post #3





Group: Members
Posts: 7
Joined: 12-August 22
Member No.: 28,503



QUOTE(Christian J @ Aug 12 2022, 01:20 PM) *

This can be done with HTTP headers, for example, by this PHP script at the very top of the HTML file (before everything else, including any whitespace):

CODE
<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>


See also
https://www.php.net/manual/en/function.header
https://www.mnot.net/cache_docs/


I did that but now, not only does the page not reload but the reload button doesn't work either


<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
etc......


PS I'm using a test page for this...
http://www.farmerskitchencafe.com/submeals...22_formail.html

This post has been edited by DDD: Aug 12 2022, 01:50 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Aug 12 2022, 06:00 PM
Post #4


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



The page isn't parsed for PHP so the line you've pasted in does nothing (more then put the page in Quirks Mode). Also, you have pasted it in twice. Once at the top of the page and once a bit down in BODY.

The reload button doesn't work because you call a function named reloadPage() but there is no such function to be found. If you meant to use the built in JS method it should be like this
CODE
window.location.reload()

or like this.
CODE
document.location.reload()


I don't remember if one is preferred over the other.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
DDD
post Aug 14 2022, 12:15 PM
Post #5





Group: Members
Posts: 7
Joined: 12-August 22
Member No.: 28,503



QUOTE(pandy @ Aug 12 2022, 06:00 PM) *

The page isn't parsed for PHP so the line you've pasted in does nothing (more then put the page in Quirks Mode). Also, you have pasted it in twice. Once at the top of the page and once a bit down in BODY.

The reload button doesn't work because you call a function named reloadPage() but there is no such function to be found. If you meant to use the built in JS method it should be like this
CODE
window.location.reload()

or like this.
CODE
document.location.reload()


I don't remember if one is preferred over the other.


Can you tell me how I would insure that my page is "parsed for PHP"?
I can remove all of the existing stuff intended to prevent page caching and start over.
I also looked at my .htaccess file and this is what is there:

# DISABLE CACHING
<IfModule mod_headers.c>
Header set Cache-Control "no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires 0
</IfModule>

This post has been edited by DDD: Aug 14 2022, 12:19 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
DDD
post Aug 14 2022, 01:18 PM
Post #6





Group: Members
Posts: 7
Joined: 12-August 22
Member No.: 28,503



FWIW, I tried removing all of the reload code and just using the php at the top of the page as suggested by "ChristianJ". Then I changed the file extention to .php. All I got from that was a 404 error!

This post has been edited by DDD: Aug 14 2022, 01:19 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
DDD
post Aug 14 2022, 02:41 PM
Post #7





Group: Members
Posts: 7
Joined: 12-August 22
Member No.: 28,503



I think I might have fixed this. I use Dreamweaver so I created a new page as a .php page instead of an .html page. Then I pasted the code "ChristianJ" provided at the top pf the page, followed by my form code. Now the page displays correctly and when I make changes, they appear without having to reload the page.

I will test this again tonight when I upload our menu for the week....
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Aug 14 2022, 06:56 PM
Post #8


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



Assuming PHP is available to you I'd say most hosts work the way that if you rename the page from *.html to *.php it will work. You can make the server parse pages with other extensions like .html too, but that's more involved.

If you view source at your page you can see the two PHP lines are still there. That shows the page is not parsed. When it works you won't see a trace of PHP when you view source. It will be replaced with what the PHP is supposed to do.

Create a new document and name it something.php. Put the below snip of PHP in it and nothing else, no HTML. Upload it to your server and call it up in your browser. If it works you'll see a pageload of info about the server. If it doesn't you'll see the PHP code.

CODE

<?php
phpinfo();
?>
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
DDD
post Aug 15 2022, 11:25 AM
Post #9





Group: Members
Posts: 7
Joined: 12-August 22
Member No.: 28,503



QUOTE(pandy @ Aug 14 2022, 06:56 PM) *

Assuming PHP is available to you I'd say most hosts work the way that if you rename the page from *.html to *.php it will work. You can make the server parse pages with other extensions like .html too, but that's more involved.

If you view source at your page you can see the two PHP lines are still there. That shows the page is not parsed. When it works you won't see a trace of PHP when you view source. It will be replaced with what the PHP is supposed to do.

Create a new document and name it something.php. Put the below snip of PHP in it and nothing else, no HTML. Upload it to your server and call it up in your browser. If it works you'll see a pageload of info about the server. If it doesn't you'll see the PHP code.

CODE

<?php
phpinfo();
?>



I just looked at the page source and no php code is displayed on the page. It now loads a “fresh” page every time. So I have essentially done what was suggested here and it seems to have solved my problem. Now all I have to do is contact our subscribers to inform them that they need to update their bookmarks to reflect the new extension!
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Aug 15 2022, 11:47 AM
Post #10


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



QUOTE(DDD @ Aug 15 2022, 06:25 PM) *

I just looked at the page source and no php code is displayed on the page. It now loads a “fresh” page every time. So I have essentially done what was suggested here and it seems to have solved my problem.

You can also view the HTTP headers being sent with this tool: https://rexswain.com/httpview.html

QUOTE
Now all I have to do is contact our subscribers to inform them that they need to update their bookmarks to reflect the new extension!

Or make the server parse PHP on pages with .html extensions. It's a simple operation, but alas details vary between servers so it's perhaps best to ask the webhost support about it.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
DDD
post Aug 15 2022, 01:55 PM
Post #11





Group: Members
Posts: 7
Joined: 12-August 22
Member No.: 28,503



Well now you are crusing a bit over my head!! But I found these instructions in my server's help files. Is this what you are getting at. This would allow me to use the .html file extension instead of .php?

https://www.siteground.com/kb/how_to_execut..._htmhtml_pages/

PS I really appreciate the help!!! This has been driving us nuts for almost two years now.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Aug 15 2022, 03:49 PM
Post #12


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



Yes that's what I meant.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Aug 15 2022, 10:11 PM
Post #13


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



You need to take care when using a .htaccess file though. It's a server config file, but on a per account or even directory basis. You can do many of the things your host do with the server config. One typo and your page won't show up.

Dot files, i.e. file names beginning with a period, are hidden files on nix systems. Or they used to be. I notice they now show up with FTP, at least for me they do. As it used to be you needed yet another file called .ftpaccess to make them visible to an FTP program. I don't know if it's just my host that use this config, or if it's common today to make them visible by default.

If it's not visible to you there are two problems. 1. You may already have a .htaccess file and if you do you don't want to overwrite what's in it with your new content, but rather edit the one you have. 2. If you make a mistake and your site disappears it's hard to delete the .htaccess if you can't see it.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Aug 16 2022, 10:11 AM
Post #14


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



QUOTE(pandy @ Aug 16 2022, 05:11 AM) *

You need to take care when using a .htaccess file though. It's a server config file, but on a per account or even directory basis.

But it does affect child directories, so for the current purpose it should be placed in the web root directory.

QUOTE
Dot files, i.e. file names beginning with a period, are hidden files on nix systems. Or they used to be. I notice they now show up with FTP, at least for me they do.

I recall Windows is sometimes uncooperative when you try to create .htaccess files. Can't remember, do you have to create a text file like "foo.htaccess" and then rename it into ".htaccess"? unsure.gif

QUOTE
As it used to be you needed yet another file called .ftpaccess to make them visible to an FTP program. I don't know if it's just my host that use this config, or if it's common today to make them visible by default.

Never heard of that. I've always seen my .htaccess files in Filezilla FTP.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Aug 16 2022, 01:12 PM
Post #15


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



You're joking? Always?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Aug 16 2022, 01:16 PM
Post #16


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,716
Joined: 9-August 06
Member No.: 6



Maybe FileZilla is the answer to the riddle.

It found this. There are FTP commands that can make them visible and FileZilla has it as a menu option. Then maybe the reason I see them is a switched to FileZilla.
https://serverfault.com/questions/942142/al...-htaccess-files

I didn't know about the commands. I always used the .ftpaccess method before.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Aug 16 2022, 02:01 PM
Post #17


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



I don't think that .ftpaccess thing has ever been mentioned on this forum before. tongue.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 28th March 2024 - 09:48 AM