Recent Posts
Archives
Topics

Thursday, January 15, 2009

 

HTML Cache Problem

I was working on the web site this morning, and I noticed a typo. "No problem!" I tell myself. I'll just hop on over and fix it. So I did.

I then went back to check my newly-corrected word. I wanted to see the work of my sheer genius. Okay... I know it's a single spelling correction, but it's the little things that make me happy. The problem was, it was still wrong.

Then it dawned on me... my browser was wrong. The website it self was right, but I was looking at a cached version. And all of you loyal readers out there would be seeing that typo all the time if you've been here before. My reputation would be ruined. Well... almost.

But being the perfectionist that I am, I still had to fix it. It is a simple fix, really. All I needed to do was add a line of meta data to my HTML page. If you have a server-side application -- such as a PHP page -- that needs to re-generate its information, or if you have JavaScript that updates frequently thanks to other services, you can use PRAGMA:NO-CACHE.

While this is not a 100% shot that the browser still won't cache your page, most of the popular borwsers (IE, Firefox, Safari, etc) obey the PRAGMA:NO-CACHE convention.

<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">


Just add that as the first line of your file and you're done. Oh, right... that is for HTML1.0 specification. What about HTML1.1? Well, there's the curve ball. An HTML1.1 site should use CACHE-CONTROL instead of PRAGMA.


<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">


Why? Who knows. Some geek in the world convinced another set of geeks somewhere that the name PRAGMA made no sense, so CACHE-CONTROL was adopted as the new standard. For safety and just to be sure, I usually add both of the tags to my site so that I know it will always load the latest version of my page.

Yes, I'm adding more work to my web server. Yes, I could use "EXPIRES" instead. But the amount I'm adding at this point is negligible, so I'm okay with that. I'll save EXPIRES for a future article. At least people will get the typo-corrected versions of the articles.

Labels: , ,


Comments:

Post a Comment



Links to this post:

Create a Link



<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]