Leverage Browser Caching

Yes, I guess changing the date often would get old very soon.

Maybe using “max-age” (seconds, not a date) would be a lot better.

What about?:

Yes, you understand.

As mawburn said

oh ok :grin:

How do I add this : Cache-Control: max-age=3600, must-revalidate

To this?:

 <meta http-equiv="Cache-control" content="public">
 <meta http-equiv="Expires" content="aDate" />
 <meta http-equiv="Last-Modified" content="aDate" />

IIRC you can combine them, though this looks like multiple times instead.
http://csis.pace.edu/~ctappert/cs615-02/support/Help/WML_Reference/meta.htm

Try
<meta http-equiv="Cache-control" content="public, max-age=3600, must-revalidate">

* 3600 is only 1 hour

So I have them like this: What so the pages refresh after an hour to get new content?

<meta http-equiv="Cache-control" content="public, max-age=3600, must-revalidate">
<meta http-equiv="Expires" content="public, max-age=3600, must-revalidate">
<meta http-equiv="Last-Modified" content="public, max-age=3600, must-revalidate">
Error Line 5, Column 81: Bad value Cache-control for attribute http-equiv on element meta.

…eta http-equiv="Cache-control" content="public, max-age=3600, must-revalidate">

Error Line 6, Column 75: Bad value Expires for attribute http-equiv on element meta.

<meta http-equiv="Expires" content="public, max-age=3600, must-revalidate">

Error Line 7, Column 81: Bad value Last-Modified for attribute http-equiv on element meta.

…eta http-equiv="Last-Modified" content="public, max-age=3600, must-revalidate">

Expires and Last-Modified need to be a date.

And it looks like comma separated values are not OK so more like.

<meta http-equiv="Cache-Control" content="public">
<meta http-equiv="Cache-Control" content="max-age=3600">
<meta http-equiv="Cache-Control" content="must-revalidate">

With 3600, yes

These are a lot of meta tags :joy:

<meta http-equiv="Cache-Control" content="public">
<meta http-equiv="Cache-Control" content="max-age=3600">
<meta http-equiv="Cache-Control" content="must-revalidate">
<meta http-equiv="Expires" content="public">
<meta http-equiv="Expires" content="mon, 28 sep 2015 14:30:00 GMT">
<meta http-equiv="Expires" content="must-revalidate">
<meta http-equiv="Last-Modified" content="public">
<meta http-equiv="Last-Modified" content="fri, 01 may 2015 14:30:00 GMT">
<meta http-equiv="Last-Modified" content="must-revalidate">

So I need to change the date after the expiration date to a new one when that day comes?

Do you consider “public” and “must-revalidate” as being dates?

<meta http-equiv="Last-Modified" content="fri, 01 may 2015 14:30:00 GMT">
<meta http-equiv="Last-Modified" content="fri, 01 may 2015 14:30:00 GMT">
<meta http-equiv="Last-Modified" content="fri, 01 may 2015 14:30:00 GMT">

So it should say it on all of them? or just does it need just one?

I should not put a date too far in the future right? Any recommendations on setting a good date?

It depends on your site and your content.

As I understand it, the point of browser caching is to save the browser having to request a fresh copy of your page every time somebody visits. If you have a slow connection, or you’re on mobile, you don’t want to have to download everything each time if it hasn’t changed. So the date you set will largely depend on how frequently you update the site contents.

[ot]
I’m guessing there should be a way to use PHP to insert a “x days from now” date dynamically, but as PHP is not my forte, I’ve no idea what it would be. @Mittineague - would you know if and how that would be possible?[/ot]

If PHP is being used to output the meta tags, sure.

PHP has some good Date functions, not so easy to understand at first maybe, but not all that difficult either.

PHP also has Filesystem functions that could be used to get the last-modified value.

I update their site quite frequently, so the changes will update only when it passes on that date?

Not necessarily. Anybody who’s never visited the site before will automatically see the new version. Anybody else can check for a new version by refreshing their browser. Otherwise, I think the behaviour depends on individual browsers. Up until that date they can serve a cached copy; it doesn’t mean that they must.

1 Like

Ok do I have the correct Meta tags coded?: @TechnoBear

<meta http-equiv="Cache-Control" content="public">
<meta http-equiv="Cache-Control" content="max-age=3600">
<meta http-equiv="Cache-Control" content="must-revalidate">
<meta http-equiv="Expires" content="thu, 25 june 2015 14:30:00 GMT">
<meta http-equiv="Last-Modified" content="mon, 04 may 2015 14:30:00 GMT">

I was wondering if the meta tags I coded are correct? ^

I wouldn’t know, as I don’t use them. But my (rather old) book of meta tags suggests not, as does a quick online search.

It appears that http-equiv="Cache-Control" can only take one of four values: public, private, no-cache and no-store.

It looks as if “expires” should be <meta name="expires" content="date"> but I’m not sure it’s going to do what you want. It’s purpose is apparently to tell search engines when your document will expire and should be deleted from their index.

But it also says: This is commonly used by websites who update their content frequently and want search engines to have a fresh copy of their content.

It is Google telling me to do this:

@Mittineague Do you have any suggestions in the code?