Cache the previous page?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian

    #16
    Re: Cache the previous page?

    C.J. Garibay wrote:
    [color=blue]
    > I'm pretty sure you can not manipulate a visitor's browser's
    > cache settings.[/color]

    Correct, you cannot manipulate such settings.

    --
    Brian (remove ".invalid" to email me)

    Comment

    • Brian

      #17
      Re: Cache the previous page?

      Bill H wrote:
      [color=blue]
      > 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.[/color]

      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).
      [color=blue]
      > 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.[/color]

      No. KISS (keep it simple, stupid!). :-) Use what's already available.
      [color=blue]
      > If they hit the "show units" button I want a new query to run.[/color]

      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)

      Comment

      • C.J. Garibay

        #18
        Re: Cache the previous page?

        Bill H wrote:
        [color=blue]
        > On Fri, 13 Aug 2004 21:22:04 GMT, "C.J. Garibay"
        > <cj.garibay@_RE MOVE_THIS_comca st.net> wrote:
        >
        >[color=green]
        >>Bill H wrote:
        >>
        >>[color=darkred]
        >>>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_c omcast.net> wrote:
        >>>>
        >>>>
        >>>>
        >>>>>Bill H wrote:
        >>>>>
        >>>>>
        >>>>>
        >>>>>>On Fri, 13 Aug 2004 17:10:07 GMT, "C.J. Garibay"
        >>>>>><cj.garib ay@_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;
        >>>>>>>JavaScri pt 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
        >>>>>contribute d 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. :)
        >>>[/color]
        >>
        >>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[/color]
        >[color=green]
        >>from the local cache or send a GET request to the URI to check if the[/color]
        >[color=green]
        >>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.[/color]
        >
        >
        > 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! :)
        >[/color]

        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.

        Comment

        • Bill H

          #19
          Re: Cache the previous page?

          On Fri, 13 Aug 2004 22:57:16 GMT, "C.J. Garibay"
          <cj.garibay@_RE MOVE_THIS_comca st.net> wrote:
          [color=blue]
          >Bill H wrote:
          >[color=green]
          >> On Fri, 13 Aug 2004 21:22:04 GMT, "C.J. Garibay"
          >> <cj.garibay@_RE MOVE_THIS_comca st.net> wrote:
          >>
          >>[color=darkred]
          >>>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.gariba y@_REMOVE_THIS_ comcast.net> wrote:
          >>>>>
          >>>>>
          >>>>>
          >>>>>>Bill H wrote:
          >>>>>>
          >>>>>>
          >>>>>>
          >>>>>>>On Fri, 13 Aug 2004 17:10:07 GMT, "C.J. Garibay"
          >>>>>>><cj.gari bay@_REMOVE_THI S_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;
          >>>>>>>>JavaScr ipt 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
          >>>>>>contribut ed 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
          >>>>>>beginne r.
          >>>>>>
          >>>>>>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,
          >>>
          >>>Unfortunatel y, you can't override the browser's settings. When a user
          >>>hits the back button on his browser, it will either display the content[/color]
          >>[color=darkred]
          >>>from the local cache or send a GET request to the URI to check if the[/color]
          >>[color=darkred]
          >>>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.[/color]
          >>
          >>
          >> 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! :)
          >>[/color]
          >
          >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.[/color]

          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!

          Comment

          • Brian

            #20
            Re: Cache the previous page?

            Bill H wrote:
            [color=blue]
            > 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.[/color]

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

            Covers the how's and why's of Web caching for people who publish on the Web. With FAQs.


            --
            Brian (remove ".invalid" to email me)

            Comment

            • Bill H

              #21
              Re: Cache the previous page?

              On Fri, 13 Aug 2004 17:57:54 -0400, Brian
              <usenet3@juliet remblay.com.inv alid> wrote:
              [color=blue]
              >Bill H wrote:
              >[color=green]
              >> 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?[/color]
              >
              >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("Cach e-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("Cach e-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[/color]

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

              Cheers,
              Bill

              Comment

              • Brian

                #22
                Re: Cache the previous page?

                Bill H wrote:[color=blue]
                > Brian wrote:
                >[color=green]
                >> The cache-control stuff is dead easy. The Last-Modified stuff
                >> is a little dicey,[/color]
                >
                > This was too easy,[/color]

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

                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)

                Comment

                Working...