Is there a web master amongst us?

This forum is for anything not Reason related, if you just want to talk about other stuff. Please keep it friendly!
Post Reply
User avatar
BarbaraC
Posts: 35
Joined: 16 Jan 2015
Location: East Greenbush, NY
Contact:

29 Jan 2015

It used to be that we could tell a browser to not dip into a person's cache for pages that change quite often. For reasons unknown to me, browsers no longer support this. However, I can see that it's being done somehow because you can go to an online store in the morning and then go back in the afternoon to find updated pages.

I have several pages on my web site that can change from day to day, but I know for a fact that most of my visitors never bother to clear their cache. Probably don't even know they should.

I tried the code where you can force a refresh every x seconds, but the problem with it is that it continues to do so every x seconds. I want it to happen just once and be done with it. If not that, at least have the refresh occur at the start and then every 5 minutes or whatever, giving the person enough time to get off the page before it refreshes again.

Why the hell did they eliminate the no-cache option?! :?

User avatar
ScuzzyEye
Moderator
Posts: 1402
Joined: 15 Jan 2015
Contact:

29 Jan 2015

Where are you specifying "no-cache"? If it's in a meta tag in the HTML document, that's always been hit and miss.

But as far as I know, sending the HTTP headers:

Pragma: no-cache
Cache-Control: no-cache, must-revalidate, no-store

Make the browser retrieve the document every time.

One other thing to be sure of, is to make sure the server is sending the "Last-Modified" header, and responding to "If-Modified-Since" queries correctly for the documents. The last one is important. Most browsers do a "If-Modified-Since" before requesting the document. If the server responds, "304 Not Modified", then the document will be retrieved from cache. A lot of scripts that dynamically generate content don't provide the right headers, or allow the server to respond correctly.

User avatar
BarbaraC
Posts: 35
Joined: 16 Jan 2015
Location: East Greenbush, NY
Contact:

29 Jan 2015

Thank you! This time when testing, I'll create an unlinked page so I don't have to rush out to do damage control like I did this morning. I had sent the index page into such a tizzy that I turned into my avatar. I hate looking like a freaked-out duck.

User avatar
ScuzzyEye
Moderator
Posts: 1402
Joined: 15 Jan 2015
Contact:

29 Jan 2015

The Pragma header should also be "no-cache" with the hyphen (I've edited it above). Though that likely doesn't matter, as the Pragma headers are simply recommendations as to what the browser should do. The Cache-Control header is more forceful, and the browser must follow it, as long as it is possible.

User avatar
BarbaraC
Posts: 35
Joined: 16 Jan 2015
Location: East Greenbush, NY
Contact:

30 Jan 2015

This works out well. I was too tired to do anything technical last night, so I copied your post, leaving it for this morning. I'm recopying and heading off shortly to create that unlinked page I mentioned and will let you know the results. Again, thank you.

Barbara

User avatar
BarbaraC
Posts: 35
Joined: 16 Jan 2015
Location: East Greenbush, NY
Contact:

30 Jan 2015

Almost there! The test page, even though I made sure it was in my cache, showed the new version when I added the code. (Yes!) However, the top of the page displayed the code as if I'd placed it there on purpose as plain text, saying at the top for anyone to see: "Pragma: no-cache Cache-Control: no-cache, must-revalidate, no-store"

Here's a shortened version of the header in which I deleted a lot of boring meta stuff and where I've highlighted the extra code:



Testing Cache








Pragma: no-cache
Cache-Control: no-cache, must-revalidate, no-store


...and so on down to the body section.

User avatar
ScuzzyEye
Moderator
Posts: 1402
Joined: 15 Jan 2015
Contact:

30 Jan 2015

Hmmm, yeah...

I was afraid this would be the only control you'd have over the HTML. You can't actually put "HTTP headers" in an HTML document. This is the stuff that needs to be sent by the server before the document even starts.

When a web browser requests a document from a server there's a bit sent before the HTML. It ended with a blank line, and then the HTML starts. These things tell the web browser what to expect, or in this case what to do (not cache).

Since you don't have control over the HTTP headers, you can try adding them to meta tags, if you have access to that.

What you want would be something like this:

User avatar
ScuzzyEye
Moderator
Posts: 1402
Joined: 15 Jan 2015
Contact:

30 Jan 2015

Gah, this editor on here is making me mad, after I copied and pasted, but I think I got all the details right now, I just can't add any more normal text to the end of my post. It all ends up in the code section.

I just wanted to add...

As I said, I've not had as much luck putting these things in meta tags in the HTML header section, but it may be your only option.

User avatar
BarbaraC
Posts: 35
Joined: 16 Jan 2015
Location: East Greenbush, NY
Contact:

30 Jan 2015

After I wrote my post, and though I didn't understand the whole process, I suspected I might have to place it in meta tags.

I wonder why the ability to stop the browser from dipping into the cache existed during slow internet days, and now that it's a whole lot faster, we've all but lost the ability. Ticks me right off.

Thank you for giving it a shot. Now it's my turn to do so.

User avatar
BarbaraC
Posts: 35
Joined: 16 Jan 2015
Location: East Greenbush, NY
Contact:

30 Jan 2015

The first test worked! :s0221:


User avatar
BarbaraC
Posts: 35
Joined: 16 Jan 2015
Location: East Greenbush, NY
Contact:

30 Jan 2015

I was thinking of changing my avatar to a happy quacker, but it would probably cause bad karma.

You're currently the man of my hour.

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 14 guests