By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,782 Members | 1,328 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,782 IT Pros & Developers. It's quick & easy.

Cache the previous page?

P: n/a
I have a routine that displays 60 items (with thumbnails) per page.
You can click any item and displays a new page with item details. When
the user back pages it runs the query again to display all the items.
Is there a way to cache that page and images so that second query
doesn't execute?

I do offer a pop-up window using Java but is not the default and not
used by many. I'd really like to get rid of that second query. ;)

TIA
Jul 17 '05 #1
Share this Question
Share on Google+
21 Replies


P: n/a
Nel
"Bill H" <maylar69@hot----.com> wrote in message
news:fu********************************@4ax.com...
I have a routine that displays 60 items (with thumbnails) per page.
You can click any item and displays a new page with item details. When
the user back pages it runs the query again to display all the items.
Is there a way to cache that page and images so that second query
doesn't execute?

I do offer a pop-up window using Java but is not the default and not
used by many. I'd really like to get rid of that second query. ;)

TIA


Why would you want to do that? Am I missing something here?

The thumbnails should all be cached by the browser anyway.

Nel.
Jul 17 '05 #2

P: n/a
Some cache options are under the control of the web browser and therefore
set by the user. In Internet Explorer, for example, under Tools->Internet
Options->Settings under the heading "check for newer versions of stored
pages" there are 4 choices:
- Every visit to the page
- Every time you start Internet Explorer
- Automatically
- Never

If you try to override the user's settings they might not be happy.

--
Tony Marston

http://www.tonymarston.net

"Bill H" <maylar69@hot----.com> wrote in message
news:fu********************************@4ax.com...
I have a routine that displays 60 items (with thumbnails) per page.
You can click any item and displays a new page with item details. When
the user back pages it runs the query again to display all the items.
Is there a way to cache that page and images so that second query
doesn't execute?

I do offer a pop-up window using Java but is not the default and not
used by many. I'd really like to get rid of that second query. ;)

TIA

Jul 17 '05 #3

P: n/a
On Fri, 13 Aug 2004 14:36:07 +0100, "Nel" <ne***@ne14.co.NOSPAMuk>
wrote:
"Bill H" <maylar69@hot----.com> wrote in message
news:fu********************************@4ax.com.. .
I have a routine that displays 60 items (with thumbnails) per page.
You can click any item and displays a new page with item details. When
the user back pages it runs the query again to display all the items.
Is there a way to cache that page and images so that second query
doesn't execute?

I do offer a pop-up window using Java but is not the default and not
used by many. I'd really like to get rid of that second query. ;)

TIA


Why would you want to do that? Am I missing something here?

The thumbnails should all be cached by the browser anyway.

Nel.


Yes, I realize the images are cached - I'm more interested in not
doing the query then I am the bandwidth. It's a large query that hits
a lot of rows and running it again on a simple back page simple seems
a waste.
Jul 17 '05 #4

P: n/a
On Fri, 13 Aug 2004 15:57:38 +0100, "Tony Marston"
<to**@NOSPAM.demon.co.uk> wrote:
Some cache options are under the control of the web browser and therefore
set by the user. In Internet Explorer, for example, under Tools->Internet
Options->Settings under the heading "check for newer versions of stored
pages" there are 4 choices:
- Every visit to the page
- Every time you start Internet Explorer
- Automatically
- Never

If you try to override the user's settings they might not be happy.


Understood, but I might like to give it a try on this one page... I'm
not sure how to override one page with "never." Maybe this would be
better asked in the HTML group. (in fact, I have an HTML book in this
pile somewhere) ;)

Thanks for the thought Tony! :)

Jul 17 '05 #5

P: n/a
Bill H wrote:
I have a routine that displays 60 items (with thumbnails) per page.
You can click any item and displays a new page with item details. When
the user back pages it runs the query again to display all the items.
Is there a way to cache that page and images so that second query
doesn't execute?

I do offer a pop-up window using Java but is not the default and not
used by many. I'd really like to get rid of that second query. ;)

TIA


Bill,

You could use a cookie to determine if the visitor has already seen the
page, then have your php act accordingly.

Why are you using Java for a pop-up window? That seems like overkill;
JavaScript would make more sense.

C.J.
Jul 17 '05 #6

P: n/a
On Fri, 13 Aug 2004 17:10:07 GMT, "C.J. Garibay"
<cj.garibay@_REMOVE_THIS_comcast.net> wrote:
Bill H wrote:
I have a routine that displays 60 items (with thumbnails) per page.
You can click any item and displays a new page with item details. When
the user back pages it runs the query again to display all the items.
Is there a way to cache that page and images so that second query
doesn't execute?

I do offer a pop-up window using Java but is not the default and not
used by many. I'd really like to get rid of that second query. ;)

TIA


Bill,

You could use a cookie to determine if the visitor has already seen the
page, then have your php act accordingly.

Why are you using Java for a pop-up window? That seems like overkill;
JavaScript would make more sense.

C.J.


So sorry, I meant JS.

That sounds like a good approach I'm simply not clear on the "how to."
I fairly now to creating apps for the Internet (yes, it shows ;)). How
would one Google this? I don't mean to be stupid but.... ;) :)

Jul 17 '05 #7

P: n/a
In message <fu********************************@4ax.com>, Bill H
<maylar69@hot----.com> writes
I have a routine that displays 60 items (with thumbnails) per page.
You can click any item and displays a new page with item details. When
the user back pages it runs the query again to display all the items.
Is there a way to cache that page and images so that second query
doesn't execute?


In cases like this, I store an array of the resultant ids in the
session, then run you just need to run a much easier query to pull out
the data for a page redisplay.
--
Rob...
Jul 17 '05 #8

P: n/a
Bill H wrote:
On Fri, 13 Aug 2004 17:10:07 GMT, "C.J. Garibay"
<cj.garibay@_REMOVE_THIS_comcast.net> wrote:

Bill H wrote:

I have a routine that displays 60 items (with thumbnails) per page.
You can click any item and displays a new page with item details. When
the user back pages it runs the query again to display all the items.
Is there a way to cache that page and images so that second query
doesn't execute?

I do offer a pop-up window using Java but is not the default and not
used by many. I'd really like to get rid of that second query. ;)

TIA


Bill,

You could use a cookie to determine if the visitor has already seen the
page, then have your php act accordingly.

Why are you using Java for a pop-up window? That seems like overkill;
JavaScript would make more sense.

C.J.

So sorry, I meant JS.

That sounds like a good approach I'm simply not clear on the "how to."
I fairly now to creating apps for the Internet (yes, it shows ;)). How
would one Google this? I don't mean to be stupid but.... ;) :)


If you're fairly new to creating web apps, this may take a little work
on your part. Your best bet is to read through the relevant parts of
the online PHP documentation (which is excellent and has user
contributed examples), and then Google anything in the documentation you
don't understand.

Main PHP documentation:
http://www.php.net/manual/en/index.php

PHP cookies function:
http://www.php.net/manual/en/function.setcookie.php

PHP sessions:
http://www.php.net/manual/en/ref.session.php

As far as the "how to" is concerned, what you're doing is referred to as
keeping track of the user's state. There are generally two ways to do
this -- cookies, or sessions. Cookies may be the easier way to go for a
beginner.

When the visitor first visits your page, your PHP script should check
for the presence of a cookie that's associated with that page. If the
user _doesn't_ have a cookie, then the PHP script runs it's query,
decides what images to send for that page and also sends a cookie with
the location of those images. If the user _does_ have a cookie for that
page, then the PHP script just sends the images that are listed in the
cookie instead of running another query.

C.J.
Jul 17 '05 #9

P: n/a
On Fri, 13 Aug 2004 19:36:01 GMT, "C.J. Garibay"
<cj.garibay@_REMOVE_THIS_comcast.net> wrote:
Bill H wrote:
On Fri, 13 Aug 2004 17:10:07 GMT, "C.J. Garibay"
<cj.garibay@_REMOVE_THIS_comcast.net> wrote:

Bill H wrote:
I have a routine that displays 60 items (with thumbnails) per page.
You can click any item and displays a new page with item details. When
the user back pages it runs the query again to display all the items.
Is there a way to cache that page and images so that second query
doesn't execute?

I do offer a pop-up window using Java but is not the default and not
used by many. I'd really like to get rid of that second query. ;)

TIA

Bill,

You could use a cookie to determine if the visitor has already seen the
page, then have your php act accordingly.

Why are you using Java for a pop-up window? That seems like overkill;
JavaScript would make more sense.

C.J.

So sorry, I meant JS.

That sounds like a good approach I'm simply not clear on the "how to."
I fairly now to creating apps for the Internet (yes, it shows ;)). How
would one Google this? I don't mean to be stupid but.... ;) :)


If you're fairly new to creating web apps, this may take a little work
on your part. Your best bet is to read through the relevant parts of
the online PHP documentation (which is excellent and has user
contributed examples), and then Google anything in the documentation you
don't understand.

Main PHP documentation:
http://www.php.net/manual/en/index.php

PHP cookies function:
http://www.php.net/manual/en/function.setcookie.php

PHP sessions:
http://www.php.net/manual/en/ref.session.php

As far as the "how to" is concerned, what you're doing is referred to as
keeping track of the user's state. There are generally two ways to do
this -- cookies, or sessions. Cookies may be the easier way to go for a
beginner.

When the visitor first visits your page, your PHP script should check
for the presence of a cookie that's associated with that page. If the
user _doesn't_ have a cookie, then the PHP script runs it's query,
decides what images to send for that page and also sends a cookie with
the location of those images. If the user _does_ have a cookie for that
page, then the PHP script just sends the images that are listed in the
cookie instead of running another query.

C.J.


Thanks so much for the reply. I know sessions and cookies, where I'm
at a bit of a loss is the mechanics of sending the user back to a
cached page instead of executing the query.

Wouldn't 'referer' or JS "back page" be good in-so-much as I only want
to address a back page not if they have visited the page. If they hit
the "show units" button I want a new query to run.

It's this only back page to a cached page that I'm a little at a loss
about - did any of that make sense? ;) :)

Jul 17 '05 #10

P: n/a
On Fri, 13 Aug 2004 19:56:30 GMT, Bill H <maylar69@hot----.com> wrote:
On Fri, 13 Aug 2004 19:36:01 GMT, "C.J. Garibay"
<cj.garibay@_REMOVE_THIS_comcast.net> wrote:
Bill H wrote:
On Fri, 13 Aug 2004 17:10:07 GMT, "C.J. Garibay"
<cj.garibay@_REMOVE_THIS_comcast.net> wrote:
Bill H wrote:
>I have a routine that displays 60 items (with thumbnails) per page.
>You can click any item and displays a new page with item details. When
>the user back pages it runs the query again to display all the items.
>Is there a way to cache that page and images so that second query
>doesn't execute?
>
>I do offer a pop-up window using Java but is not the default and not
>used by many. I'd really like to get rid of that second query. ;)
>
>TIA

Bill,

You could use a cookie to determine if the visitor has already seen the
page, then have your php act accordingly.

Why are you using Java for a pop-up window? That seems like overkill;
JavaScript would make more sense.

C.J.
So sorry, I meant JS.

That sounds like a good approach I'm simply not clear on the "how to."
I fairly now to creating apps for the Internet (yes, it shows ;)). How
would one Google this? I don't mean to be stupid but.... ;) :)


If you're fairly new to creating web apps, this may take a little work
on your part. Your best bet is to read through the relevant parts of
the online PHP documentation (which is excellent and has user
contributed examples), and then Google anything in the documentation you
don't understand.

Main PHP documentation:
http://www.php.net/manual/en/index.php

PHP cookies function:
http://www.php.net/manual/en/function.setcookie.php

PHP sessions:
http://www.php.net/manual/en/ref.session.php

As far as the "how to" is concerned, what you're doing is referred to as
keeping track of the user's state. There are generally two ways to do
this -- cookies, or sessions. Cookies may be the easier way to go for a
beginner.

When the visitor first visits your page, your PHP script should check
for the presence of a cookie that's associated with that page. If the
user _doesn't_ have a cookie, then the PHP script runs it's query,
decides what images to send for that page and also sends a cookie with
the location of those images. If the user _does_ have a cookie for that
page, then the PHP script just sends the images that are listed in the
cookie instead of running another query.

C.J.


Thanks so much for the reply. I know sessions and cookies, where I'm
at a bit of a loss is the mechanics of sending the user back to a
cached page instead of executing the query.

Wouldn't 'referer' or JS "back page" be good in-so-much as I only want
to address a back page not if they have visited the page. If they hit
the "show units" button I want a new query to run.

It's this only back page to a cached page that I'm a little at a loss
about - did any of that make sense? ;) :)


hmmm I see holes in my approach here... if a user hits "back page" on
a specfic page is there a way to temporary overide browser settings
and not refresh?

So I come in the top run the query, drop a cookie that says "kilroy
was here" and then overide the browser setting on the next pass if the
cookie is present. Now the how to overide part, should I ask that in
HTML group? Maybe I have enough of a clue now to Google. :)

Jul 17 '05 #11

P: n/a
Bill H wrote:
On Fri, 13 Aug 2004 19:56:30 GMT, Bill H <maylar69@hot----.com> wrote:

On Fri, 13 Aug 2004 19:36:01 GMT, "C.J. Garibay"
<cj.garibay@_REMOVE_THIS_comcast.net> wrote:

Bill H wrote:
On Fri, 13 Aug 2004 17:10:07 GMT, "C.J. Garibay"
<cj.garibay@_REMOVE_THIS_comcast.net> wrote:

>Bill H wrote:
>
>
>
>>I have a routine that displays 60 items (with thumbnails) per page.
>>You can click any item and displays a new page with item details. When
>>the user back pages it runs the query again to display all the items.
>>Is there a way to cache that page and images so that second query
>>doesn't execute?
>>
>>I do offer a pop-up window using Java but is not the default and not
>>used by many. I'd really like to get rid of that second query. ;)
>>
>>TIA
>
>Bill,
>
>You could use a cookie to determine if the visitor has already seen the
>page, then have your php act accordingly.
>
>Why are you using Java for a pop-up window? That seems like overkill;
>JavaScript would make more sense.
>
>C.J.
So sorry, I meant JS.

That sounds like a good approach I'm simply not clear on the "how to."
I fairly now to creating apps for the Internet (yes, it shows ;)). How
would one Google this? I don't mean to be stupid but.... ;) :)
If you're fairly new to creating web apps, this may take a little work
on your part. Your best bet is to read through the relevant parts of
the online PHP documentation (which is excellent and has user
contributed examples), and then Google anything in the documentation you
don't understand.

Main PHP documentation:
http://www.php.net/manual/en/index.php

PHP cookies function:
http://www.php.net/manual/en/function.setcookie.php

PHP sessions:
http://www.php.net/manual/en/ref.session.php

As far as the "how to" is concerned, what you're doing is referred to as
keeping track of the user's state. There are generally two ways to do
this -- cookies, or sessions. Cookies may be the easier way to go for a
beginner.

When the visitor first visits your page, your PHP script should check
for the presence of a cookie that's associated with that page. If the
user _doesn't_ have a cookie, then the PHP script runs it's query,
decides what images to send for that page and also sends a cookie with
the location of those images. If the user _does_ have a cookie for that
page, then the PHP script just sends the images that are listed in the
cookie instead of running another query.

C.J.


Thanks so much for the reply. I know sessions and cookies, where I'm
at a bit of a loss is the mechanics of sending the user back to a
cached page instead of executing the query.

Wouldn't 'referer' or JS "back page" be good in-so-much as I only want
to address a back page not if they have visited the page. If they hit
the "show units" button I want a new query to run.

It's this only back page to a cached page that I'm a little at a loss
about - did any of that make sense? ;) :)

hmmm I see holes in my approach here... if a user hits "back page" on
a specfic page is there a way to temporary overide browser settings
and not refresh?

So I come in the top run the query, drop a cookie that says "kilroy
was here" and then overide the browser setting on the next pass if the
cookie is present. Now the how to overide part, should I ask that in
HTML group? Maybe I have enough of a clue now to Google. :)


Bill,

Unfortunately, you can't override the browser's settings. When a user
hits the back button on his browser, it will either display the content
from the local cache or send a GET request to the URI to check if the
page has changed since it was last cached locally (depending on how the
browser's cache settings are set).

The only thing you have control over in this situation is your server.
So if your server is hit with another GET request, your only recourse is
to check the visitor's state to see if he's already requested the URI in
question.

There _may_ be a way to override a browser's cache settings using
JavaScript (emphasis on may), but I doubt it. At any rate, PHP is
definitely unable to affect a browser's cache settings.

You can check with an HTML newsgroup or JavaScript newsgroup (or even an
IE and/or Mozilla newsgroup), but I'm pretty sure you can not manipulate
a visitor's browser's cache settings.

C.J.
Jul 17 '05 #12

P: n/a
On Fri, 13 Aug 2004 21:22:04 GMT, "C.J. Garibay"
<cj.garibay@_REMOVE_THIS_comcast.net> wrote:
Bill H wrote:
On Fri, 13 Aug 2004 19:56:30 GMT, Bill H <maylar69@hot----.com> wrote:

On Fri, 13 Aug 2004 19:36:01 GMT, "C.J. Garibay"
<cj.garibay@_REMOVE_THIS_comcast.net> wrote:
Bill H wrote:
>On Fri, 13 Aug 2004 17:10:07 GMT, "C.J. Garibay"
><cj.garibay@_REMOVE_THIS_comcast.net> wrote:
>
>
>
>>Bill H wrote:
>>
>>
>>
>>>I have a routine that displays 60 items (with thumbnails) per page.
>>>You can click any item and displays a new page with item details. When
>>>the user back pages it runs the query again to display all the items.
>>>Is there a way to cache that page and images so that second query
>>>doesn't execute?
>>>
>>>I do offer a pop-up window using Java but is not the default and not
>>>used by many. I'd really like to get rid of that second query. ;)
>>>
>>>TIA
>>
>>Bill,
>>
>>You could use a cookie to determine if the visitor has already seen the
>>page, then have your php act accordingly.
>>
>>Why are you using Java for a pop-up window? That seems like overkill;
>>JavaScript would make more sense.
>>
>>C.J.
>
>
>So sorry, I meant JS.
>
>That sounds like a good approach I'm simply not clear on the "how to."
>I fairly now to creating apps for the Internet (yes, it shows ;)). How
>would one Google this? I don't mean to be stupid but.... ;) :)
>

If you're fairly new to creating web apps, this may take a little work
on your part. Your best bet is to read through the relevant parts of
the online PHP documentation (which is excellent and has user
contributed examples), and then Google anything in the documentation you
don't understand.

Main PHP documentation:
http://www.php.net/manual/en/index.php

PHP cookies function:
http://www.php.net/manual/en/function.setcookie.php

PHP sessions:
http://www.php.net/manual/en/ref.session.php

As far as the "how to" is concerned, what you're doing is referred to as
keeping track of the user's state. There are generally two ways to do
this -- cookies, or sessions. Cookies may be the easier way to go for a
beginner.

When the visitor first visits your page, your PHP script should check
for the presence of a cookie that's associated with that page. If the
user _doesn't_ have a cookie, then the PHP script runs it's query,
decides what images to send for that page and also sends a cookie with
the location of those images. If the user _does_ have a cookie for that
page, then the PHP script just sends the images that are listed in the
cookie instead of running another query.

C.J.

Thanks so much for the reply. I know sessions and cookies, where I'm
at a bit of a loss is the mechanics of sending the user back to a
cached page instead of executing the query.

Wouldn't 'referer' or JS "back page" be good in-so-much as I only want
to address a back page not if they have visited the page. If they hit
the "show units" button I want a new query to run.

It's this only back page to a cached page that I'm a little at a loss
about - did any of that make sense? ;) :)

hmmm I see holes in my approach here... if a user hits "back page" on
a specfic page is there a way to temporary overide browser settings
and not refresh?

So I come in the top run the query, drop a cookie that says "kilroy
was here" and then overide the browser setting on the next pass if the
cookie is present. Now the how to overide part, should I ask that in
HTML group? Maybe I have enough of a clue now to Google. :)


Bill,

Unfortunately, you can't override the browser's settings. When a user
hits the back button on his browser, it will either display the content
from the local cache or send a GET request to the URI to check if the
page has changed since it was last cached locally (depending on how the
browser's cache settings are set).

The only thing you have control over in this situation is your server.
So if your server is hit with another GET request, your only recourse is
to check the visitor's state to see if he's already requested the URI in
question.

There _may_ be a way to override a browser's cache settings using
JavaScript (emphasis on may), but I doubt it. At any rate, PHP is
definitely unable to affect a browser's cache settings.

You can check with an HTML newsgroup or JavaScript newsgroup (or even an
IE and/or Mozilla newsgroup), but I'm pretty sure you can not manipulate
a visitor's browser's cache settings.

C.J.


Roger that C.J.

Actually Rob Allen offered a smart solution that I have to believe
would have dawned on me at some point. ;) That is to save the result
ID's of the query to an array and simply use those when the user
returns... thanks Rob! :)

Jul 17 '05 #13

P: n/a
On Fri, 13 Aug 2004 19:32:44 +0100, Rob Allen <ro***@the-allens.net>
wrote:
In message <fu********************************@4ax.com>, Bill H
<maylar69@hot----.com> writes
I have a routine that displays 60 items (with thumbnails) per page.
You can click any item and displays a new page with item details. When
the user back pages it runs the query again to display all the items.
Is there a way to cache that page and images so that second query
doesn't execute?


In cases like this, I store an array of the resultant ids in the
session, then run you just need to run a much easier query to pull out
the data for a page redisplay.


Thanks Rob!

As I said in another post on this topic I have to believe this would
have dawned on me at some point! ;) :)

Thank you,
Bill

Jul 17 '05 #14

P: n/a
Bill H wrote:
I have a routine that displays 60 items (with thumbnails) per page.
You can click any item and displays a new page with item details.
When the user back pages it runs the query again to display all the
items. Is there a way to cache that page and images so that second
query doesn't execute?


Of course, using standard http cache headers. The simplest method for
images is to store them as static files, and let your server do the
work. Be sure to configure the server to set explicit freshness info for
maximum caching. For the page that displays the thumbs and data, you can
use cache-control headers.

<?php
header("Cache-Control: max-age=600"); // 10 minutes
?>

The time should take into account how often you update the data on which
the query is based. If it's only once per week, then increase the
cache-control max-age value to a couple of hours. NB: Headers *must* be
sent **before** any data is sent.
<?php
header("Cache-Control: max-age=7200"); // 2 hours
?>

This may accomplish what you want without further fuss. If you want to
do more, then consider determining when you last modified the data, and
send a Last-Modified header. Then, when there's a request for the
thumbnails page, process the request headers, looking for
If-Modified-Since. If the user's copy is still fresh, send "304 Not
Modified" and exit the script.

I've done all this -- and for sevearal pages with thumbnails, as well
for individual photo pages and a catalogue -- for a photography site:

http://www.julietremblay.com/

The cache-control stuff is dead easy. The Last-Modified stuff is a
little dicey, but if you're serious, then give it a try. Feel free to
ask me if you run into trouble. I have links plus my own code to offer.

HTH

--
Brian (remove ".invalid" to email me)
http://www.tsmchughs.com/
Jul 17 '05 #15

P: n/a
C.J. Garibay wrote:
I'm pretty sure you can not manipulate a visitor's browser's
cache settings.


Correct, you cannot manipulate such settings.

--
Brian (remove ".invalid" to email me)
http://www.tsmchughs.com/
Jul 17 '05 #16

P: n/a
Bill H wrote:
I know sessions and cookies, where I'm at a bit of a loss is the
mechanics of sending the user back to a cached page instead of
executing the query.
You don't need sessions, nor cookies, to encourage caching. In fact,
they are likely to *prevent* caching. See my other response for how to
encourage caching by user-agents (and proxies).
Wouldn't 'referer' or JS "back page" be good in-so-much as I only
want to address a back page not if they have visited the page.
No. KISS (keep it simple, stupid!). :-) Use what's already available.
If they hit the "show units" button I want a new query to run.


I'm afraid I don't know what this button does. You'll need to provide a
url if I need to see this part to help you.

--
Brian (remove ".invalid" to email me)
http://www.tsmchughs.com/
Jul 17 '05 #17

P: n/a
Bill H wrote:
On Fri, 13 Aug 2004 21:22:04 GMT, "C.J. Garibay"
<cj.garibay@_REMOVE_THIS_comcast.net> wrote:

Bill H wrote:

On Fri, 13 Aug 2004 19:56:30 GMT, Bill H <maylar69@hot----.com> wrote:

On Fri, 13 Aug 2004 19:36:01 GMT, "C.J. Garibay"
<cj.garibay@_REMOVE_THIS_comcast.net> wrote:

>Bill H wrote:
>
>
>
>>On Fri, 13 Aug 2004 17:10:07 GMT, "C.J. Garibay"
>><cj.garibay@_REMOVE_THIS_comcast.net> wrote:
>>
>>
>>
>>
>>>Bill H wrote:
>>>
>>>
>>>
>>>
>>>>I have a routine that displays 60 items (with thumbnails) per page.
>>>>You can click any item and displays a new page with item details. When
>>>>the user back pages it runs the query again to display all the items.
>>>>Is there a way to cache that page and images so that second query
>>>>doesn't execute?
>>>>
>>>>I do offer a pop-up window using Java but is not the default and not
>>>>used by many. I'd really like to get rid of that second query. ;)
>>>>
>>>>TIA
>>>
>>>Bill,
>>>
>>>You could use a cookie to determine if the visitor has already seen the
>>>page, then have your php act accordingly.
>>>
>>>Why are you using Java for a pop-up window? That seems like overkill;
>>>JavaScript would make more sense.
>>>
>>>C.J.
>>
>>
>>So sorry, I meant JS.
>>
>>That sounds like a good approach I'm simply not clear on the "how to."
>>I fairly now to creating apps for the Internet (yes, it shows ;)). How
>>would one Google this? I don't mean to be stupid but.... ;) :)
>>
>
>If you're fairly new to creating web apps, this may take a little work
>on your part. Your best bet is to read through the relevant parts of
>the online PHP documentation (which is excellent and has user
>contributed examples), and then Google anything in the documentation you
>don't understand.
>
>Main PHP documentation:
>http://www.php.net/manual/en/index.php
>
>PHP cookies function:
>http://www.php.net/manual/en/function.setcookie.php
>
>PHP sessions:
>http://www.php.net/manual/en/ref.session.php
>
>As far as the "how to" is concerned, what you're doing is referred to as
>keeping track of the user's state. There are generally two ways to do
>this -- cookies, or sessions. Cookies may be the easier way to go for a
>beginner.
>
>When the visitor first visits your page, your PHP script should check
>for the presence of a cookie that's associated with that page. If the
>user _doesn't_ have a cookie, then the PHP script runs it's query,
>decides what images to send for that page and also sends a cookie with
>the location of those images. If the user _does_ have a cookie for that
>page, then the PHP script just sends the images that are listed in the
>cookie instead of running another query.
>
>C.J.

Thanks so much for the reply. I know sessions and cookies, where I'm
at a bit of a loss is the mechanics of sending the user back to a
cached page instead of executing the query.

Wouldn't 'referer' or JS "back page" be good in-so-much as I only want
to address a back page not if they have visited the page. If they hit
the "show units" button I want a new query to run.

It's this only back page to a cached page that I'm a little at a loss
about - did any of that make sense? ;) :)
hmmm I see holes in my approach here... if a user hits "back page" on
a specfic page is there a way to temporary overide browser settings
and not refresh?

So I come in the top run the query, drop a cookie that says "kilroy
was here" and then overide the browser setting on the next pass if the
cookie is present. Now the how to overide part, should I ask that in
HTML group? Maybe I have enough of a clue now to Google. :)


Bill,

Unfortunately, you can't override the browser's settings. When a user
hits the back button on his browser, it will either display the content

from the local cache or send a GET request to the URI to check if the

page has changed since it was last cached locally (depending on how the
browser's cache settings are set).

The only thing you have control over in this situation is your server.
So if your server is hit with another GET request, your only recourse is
to check the visitor's state to see if he's already requested the URI in
question.

There _may_ be a way to override a browser's cache settings using
JavaScript (emphasis on may), but I doubt it. At any rate, PHP is
definitely unable to affect a browser's cache settings.

You can check with an HTML newsgroup or JavaScript newsgroup (or even an
IE and/or Mozilla newsgroup), but I'm pretty sure you can not manipulate
a visitor's browser's cache settings.

C.J.

Roger that C.J.

Actually Rob Allen offered a smart solution that I have to believe
would have dawned on me at some point. ;) That is to save the result
ID's of the query to an array and simply use those when the user
returns... thanks Rob! :)


Well, that's what I was trying to suggest when I said:

"If the user _doesn't_ have a cookie, then the PHP script runs it's
query, decides what images to send for that page and also sends a cookie
with he location of those images."

C.J.
Jul 17 '05 #18

P: n/a
On Fri, 13 Aug 2004 22:57:16 GMT, "C.J. Garibay"
<cj.garibay@_REMOVE_THIS_comcast.net> wrote:
Bill H wrote:
On Fri, 13 Aug 2004 21:22:04 GMT, "C.J. Garibay"
<cj.garibay@_REMOVE_THIS_comcast.net> wrote:

Bill H wrote:
On Fri, 13 Aug 2004 19:56:30 GMT, Bill H <maylar69@hot----.com> wrote:

>On Fri, 13 Aug 2004 19:36:01 GMT, "C.J. Garibay"
><cj.garibay@_REMOVE_THIS_comcast.net> wrote:
>
>
>
>>Bill H wrote:
>>
>>
>>
>>>On Fri, 13 Aug 2004 17:10:07 GMT, "C.J. Garibay"
>>><cj.garibay@_REMOVE_THIS_comcast.net> wrote:
>>>
>>>
>>>
>>>
>>>>Bill H wrote:
>>>>
>>>>
>>>>
>>>>
>>>>>I have a routine that displays 60 items (with thumbnails) per page.
>>>>>You can click any item and displays a new page with item details. When
>>>>>the user back pages it runs the query again to display all the items.
>>>>>Is there a way to cache that page and images so that second query
>>>>>doesn't execute?
>>>>>
>>>>>I do offer a pop-up window using Java but is not the default and not
>>>>>used by many. I'd really like to get rid of that second query. ;)
>>>>>
>>>>>TIA
>>>>
>>>>Bill,
>>>>
>>>>You could use a cookie to determine if the visitor has already seen the
>>>>page, then have your php act accordingly.
>>>>
>>>>Why are you using Java for a pop-up window? That seems like overkill;
>>>>JavaScript would make more sense.
>>>>
>>>>C.J.
>>>
>>>
>>>So sorry, I meant JS.
>>>
>>>That sounds like a good approach I'm simply not clear on the "how to."
>>>I fairly now to creating apps for the Internet (yes, it shows ;)). How
>>>would one Google this? I don't mean to be stupid but.... ;) :)
>>>
>>
>>If you're fairly new to creating web apps, this may take a little work
>>on your part. Your best bet is to read through the relevant parts of
>>the online PHP documentation (which is excellent and has user
>>contributed examples), and then Google anything in the documentation you
>>don't understand.
>>
>>Main PHP documentation:
>>http://www.php.net/manual/en/index.php
>>
>>PHP cookies function:
>>http://www.php.net/manual/en/function.setcookie.php
>>
>>PHP sessions:
>>http://www.php.net/manual/en/ref.session.php
>>
>>As far as the "how to" is concerned, what you're doing is referred to as
>>keeping track of the user's state. There are generally two ways to do
>>this -- cookies, or sessions. Cookies may be the easier way to go for a
>>beginner.
>>
>>When the visitor first visits your page, your PHP script should check
>>for the presence of a cookie that's associated with that page. If the
>>user _doesn't_ have a cookie, then the PHP script runs it's query,
>>decides what images to send for that page and also sends a cookie with
>>the location of those images. If the user _does_ have a cookie for that
>>page, then the PHP script just sends the images that are listed in the
>>cookie instead of running another query.
>>
>>C.J.
>
>Thanks so much for the reply. I know sessions and cookies, where I'm
>at a bit of a loss is the mechanics of sending the user back to a
>cached page instead of executing the query.
>
>Wouldn't 'referer' or JS "back page" be good in-so-much as I only want
>to address a back page not if they have visited the page. If they hit
>the "show units" button I want a new query to run.
>
>It's this only back page to a cached page that I'm a little at a loss
>about - did any of that make sense? ;) :)
hmmm I see holes in my approach here... if a user hits "back page" on
a specfic page is there a way to temporary overide browser settings
and not refresh?

So I come in the top run the query, drop a cookie that says "kilroy
was here" and then overide the browser setting on the next pass if the
cookie is present. Now the how to overide part, should I ask that in
HTML group? Maybe I have enough of a clue now to Google. :)
Bill,

Unfortunately, you can't override the browser's settings. When a user
hits the back button on his browser, it will either display the content

from the local cache or send a GET request to the URI to check if the

page has changed since it was last cached locally (depending on how the
browser's cache settings are set).

The only thing you have control over in this situation is your server.
So if your server is hit with another GET request, your only recourse is
to check the visitor's state to see if he's already requested the URI in
question.

There _may_ be a way to override a browser's cache settings using
JavaScript (emphasis on may), but I doubt it. At any rate, PHP is
definitely unable to affect a browser's cache settings.

You can check with an HTML newsgroup or JavaScript newsgroup (or even an
IE and/or Mozilla newsgroup), but I'm pretty sure you can not manipulate
a visitor's browser's cache settings.

C.J.

Roger that C.J.

Actually Rob Allen offered a smart solution that I have to believe
would have dawned on me at some point. ;) That is to save the result
ID's of the query to an array and simply use those when the user
returns... thanks Rob! :)


Well, that's what I was trying to suggest when I said:

"If the user _doesn't_ have a cookie, then the PHP script runs it's
query, decides what images to send for that page and also sends a cookie
with he location of those images."

C.J.


lol! Sorry, it was never about the images really so it just didn't
click... I see it now. Rob spoke the language I was thinking in is
all. But I certainly thank you for offering a solution was was too dim
to see! :)

Brian is saying that I can do what I'm asking for with headers alone
with would be the easiet of course. Think I'll grab a book and bring
myself up to speed in terms of the headers.

You've all be great! and I thank all of you!

Jul 17 '05 #19

P: n/a
Bill H wrote:
Brian is saying that I can do what I'm asking for with headers alone
with would be the easiet of course. Think I'll grab a book and bring
myself up to speed in terms of the headers.


Or just go online. An excellent tutorial on caches and headers:

http://www.mnot.net/cache_docs/

--
Brian (remove ".invalid" to email me)
http://www.tsmchughs.com/
Jul 17 '05 #20

P: n/a
On Fri, 13 Aug 2004 17:57:54 -0400, Brian
<us*****@julietremblay.com.invalid> wrote:
Bill H wrote:
I have a routine that displays 60 items (with thumbnails) per page.
You can click any item and displays a new page with item details.
When the user back pages it runs the query again to display all the
items. Is there a way to cache that page and images so that second
query doesn't execute?


Of course, using standard http cache headers. The simplest method for
images is to store them as static files, and let your server do the
work. Be sure to configure the server to set explicit freshness info for
maximum caching. For the page that displays the thumbs and data, you can
use cache-control headers.

<?php
header("Cache-Control: max-age=600"); // 10 minutes
?>

The time should take into account how often you update the data on which
the query is based. If it's only once per week, then increase the
cache-control max-age value to a couple of hours. NB: Headers *must* be
sent **before** any data is sent.
<?php
header("Cache-Control: max-age=7200"); // 2 hours
?>

This may accomplish what you want without further fuss. If you want to
do more, then consider determining when you last modified the data, and
send a Last-Modified header. Then, when there's a request for the
thumbnails page, process the request headers, looking for
If-Modified-Since. If the user's copy is still fresh, send "304 Not
Modified" and exit the script.

I've done all this -- and for sevearal pages with thumbnails, as well
for individual photo pages and a catalogue -- for a photography site:

http://www.julietremblay.com/

The cache-control stuff is dead easy. The Last-Modified stuff is a
little dicey, but if you're serious, then give it a try. Feel free to
ask me if you run into trouble. I have links plus my own code to offer.

HTH


This was too easy, thanks Brian! It gives me just the behavior I was
looking for.

Cheers,
Bill
Jul 17 '05 #21

P: n/a
Bill H wrote:
Brian wrote:
The cache-control stuff is dead easy. The Last-Modified stuff
is a little dicey,
This was too easy,


Cache-control, I assume you mean. If you think parsing
If-Modified-Since is "too easy" then you're a better coder
than I!
It gives me just the behavior I was looking for.


Great! I only wish other authors were as observant and conscientious
about caching. Too many php driven sites ignore it completely, wasting
bandwidth and making their sites quite a bit slower.

--
Brian (remove ".invalid" to email me)
http://www.tsmchughs.com/
Jul 17 '05 #22

This discussion thread is closed

Replies have been disabled for this discussion.