473,748 Members | 2,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Browser caching ?

Hi guys,

Let's say I have a page that is primarily HTML but I added a few small parts
that are PHP, for example a random banner. The page is in no way PHP driven,
it just has some some random stuff like the banner and/or a tip of the day.

What bothers me is that the PHP page won't be cached, so if the page has a
lot of links and, on average, the user clicks ten links (hitting the back
button after he does that) my bandwidth usage increases tenfold.

I think I can send cache headers but I don't know much about them. Is it
possible to set it for, say, an hour so that if he hits the back button
he'll get the same banner/tip of the day that he originally got (because
he's looking at his cached page) and only after an hour will he get a new
random banner/tip ?

I'm ready to switch my pages to PHP but I don't want to get a huge bandwidth
bill.

Any guidence would be appreciated.

Take care,
Cyrus
Jul 17 '05 #1
9 2210
>Let's say I have a page that is primarily HTML but I added a few small parts
that are PHP, for example a random banner. The page is in no way PHP driven,
it just has some some random stuff like the banner and/or a tip of the day.
Can't you turn the URL that returns the *BANNER* into a PHP one,
and leave the main page alone? (The PHP selects a random image,
then returns appropriate headers and the body of the image, probably
with fpassthru()). You get 10 image hits (maybe that's what you
want) but only one hit on the main page. You could also try letting
the browser cache the images with cache headers, but I'm not sure
you want to.
What bothers me is that the PHP page won't be cached, so if the page has a
lot of links and, on average, the user clicks ten links (hitting the back
button after he does that) my bandwidth usage increases tenfold.

I think I can send cache headers but I don't know much about them. Is it
possible to set it for, say, an hour so that if he hits the back button
he'll get the same banner/tip of the day that he originally got (because
he's looking at his cached page) and only after an hour will he get a new
random banner/tip ?

I'm ready to switch my pages to PHP but I don't want to get a huge bandwidth
bill.


Gordon L. Burditt
Jul 17 '05 #2
Cyrus D. wrote:
Hi guys,

Let's say I have a page that is primarily HTML but I added a few small
parts that are PHP, for example a random banner. The page is in no way PHP
driven, it just has some some random stuff like the banner and/or a tip of
the day.

What bothers me is that the PHP page won't be cached, so if the page has a
lot of links and, on average, the user clicks ten links (hitting the back
button after he does that) my bandwidth usage increases tenfold.

I think I can send cache headers but I don't know much about them. Is it
possible to set it for, say, an hour so that if he hits the back button
he'll get the same banner/tip of the day that he originally got (because
he's looking at his cached page) and only after an hour will he get a new
random banner/tip ?

I'm ready to switch my pages to PHP but I don't want to get a huge
bandwidth bill.

Any guidence would be appreciated.


This example at http://butterflies.usenetshit.info/butterfly.phps has the
stuff you need for setting the modification dates and times and telling the
browser to use the cached version where appropriate etc. I've used a
modified version of the code in that page in both PHP and ASP and it worked
nicely.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #3
Hi Gordon,

Let's just say it's text for a random tip of the day. If I make a seperate
PHP file (URL) to return the random tip how do I link it up to my main page
?

Tip.php

<?php
function GetTip(){
//returns a string
}
?>

Main.php

lots of HTML
the tip goes here
more HTML

Sorry if I seem like a newbie.

Thanks,
Cyrus
Jul 17 '05 #4
Cyrus D. schrieb:
Tip.php

<?php
function GetTip(){
//returns a string
}
?>

Main.php

lots of HTML
the tip goes here
more HTML


Main.php

lots of HTML
<?php
include('Tip.ph p');
$result = GetTip();
echo ($result);
?>
more HTML
Matthias
Jul 17 '05 #5
Cyrus D. wrote:
Let's say I have a page that is primarily HTML but I added a few
small parts that are PHP, for example a random banner.
You already said that, in another thread. And I already answered you, in
that thread. Did you not like my responses?
The page is in no way PHP driven, it just has some some random stuff
like the banner and/or a tip of the day.
I'm not sure what you mean by this. If the page is parsed by php, then
it is php driven. Perhaps you mean that only a small part of the content
is created by php, but that only affects server processing time needed.
It is unrelated to http caching.
What bothers me is that the PHP page won't be cached,
Well, sort of. It means that the php page will not have last-modified
headers, so conditional get requests are impossible. (Didn't I explain
this adequately in the previous thread?)
so if the page has a lot of links and, on average, the user clicks
ten links (hitting the back button after he does that) my bandwidth
usage increases tenfold.
It depends on the browser settings, but this is certainly possible.
I think I can send cache headers but I don't know much about them. Is
it possible to set it for, say, an hour so that if he hits the back
button he'll get the same banner/tip of the day that he originally
got (because he's looking at his cached page) and only after an hour
will he get a new random banner/tip ?
Yes, using php's header function.

header("Cache-Control: max-age=3600");

This sends a response header to the client, as follows,

Cache-Control: max-age=3600

which tells the client that the resource is cacheable, and will be fresh
for 3600 seconds or 1 hour.
I'm ready to switch my pages to PHP
Why? Unless php is doing something critical for the page content, why
not stick with static html? ISTM that you should think about the user.
The user does not need a random banner. So unless that banner is
generating significant revenue, I'd dump the idea. If it is important,
then G. Burditt's idea may be worth exploring. Use a url for the image,
say /image/random.php, and have that url return a random image resource.
That way, the html document that includes that image can remain a static
resource, with all the benefits of http caching (hopefully!) built-in
via Apache.

As for "tip of the day", if that really is what you claim it is, and it
really changes every day, make the page fresh for that day. You may need
to look at the http 1.0 expires header instead. But without details, I
cannot offer you anything more specific.
but I don't want to get a huge bandwidth bill.


If the site is popular, then caching becomes quite critical.

--
Brian (remove "invalid" to email me)
Jul 17 '05 #6
Brian wrote:
What bothers me is that the PHP page won't be cached,


Well, sort of. It means that the php page will not have last-modified
headers, so conditional get requests are impossible. (Didn't I explain
this adequately in the previous thread?)


I'm not sure what you posted in the previous thread so this may cover some
of that as well. You can set last-modified headers with PHP but it's a
little more work than either not doing it, or letting the webserver take
care of it with static HTML files.

I have used this method in a couple of different sites (in both PHP and ASP)
and am going to create a function or class to simplify the process so I can
easily incorporate it into my other projects and will publish it on my
website when it's done.

Anyway, I won't explain it just now but instead point you to the example
code where I found it at http://butterflies.usenetshit.info/butterfly.phps

Hopefully I should have a nice function written by early next week and will
share my version of Brucie's code at that point. (Brucie's the author of
the above script).

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #7
Matthias Esken wrote:
Cyrus D. schrieb:

Tip.php

<?php
function GetTip(){
//returns a string
}
?>

Main.php

lots of HTML
the tip goes here
more HTML

Main.php

lots of HTML
<?php
include('Tip.ph p');
$result = GetTip();
echo ($result);
?>
more HTML


However, that doesn't solve the caching problem as described. If you're
worried about that side of it, you may want to generate the tip as an
image using GD or something and save it to disk - after all, it's "tip
of the day", not "tip of the request" right? ;) Otherwise, I would say
that the overhead of processing the image for every request may not be
be worthwhile... could just put the tip into an iframe and have that
point to a php script that spits it out I guess..

--
Justin Koivisto - sp**@koivi.com
http://www.koivi.com
Jul 17 '05 #8
Chris Hope wrote:
You can set last-modified headers with PHP but it's a little more
work than either not doing it, or letting the webserver take care of
it with static HTML files.

I have used this method in a couple of different sites (in both PHP
and ASP) and am going to create a function or class to simplify the
process so I can easily incorporate it into my other projects and
will publish it on my website when it's done.


Already done in php:

http://simon.incutio.com/archive/200...conditionalGet

I use a version of that script, modified a bit to do a real time
comparison instead of string matching.

--
Brian (remove "invalid" to email me)
Jul 17 '05 #9
Brian wrote:
Chris Hope wrote:
You can set last-modified headers with PHP but it's a little more
work than either not doing it, or letting the webserver take care of
it with static HTML files.

I have used this method in a couple of different sites (in both PHP
and ASP) and am going to create a function or class to simplify the
process so I can easily incorporate it into my other projects and
will publish it on my website when it's done.


Already done in php:

http://simon.incutio.com/archive/200...conditionalGet

I use a version of that script, modified a bit to do a real time
comparison instead of string matching.


Excellent, thanks. Saves me having to do it myself.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
3222
by: Tony Marston | last post by:
If the use of the browser's BACK button is interfering with the operation of your web application then take a look at this article entitle "Back Button Blues" http://www.tonymarston.co.uk/php-mysql/backbuttonblues.html -- Tony Marston http://www.tonymarston.net
2
2451
by: Michael G | last post by:
Can the browser back button or browser caching be turned on or off via php? Thanks, Mike ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
5
3138
by: R. Ian Lee | last post by:
I have an ASP.NET page that spawns a popup window using javascript's window.open. This works fine. It pops up, you enter some data, press save and everything saves as it should. But, if you click the button to open the popup again, then it opens with the values that were in it before the "save" was executed. I've determined that the problem is that IE is storing the page in it's local temporary internet files cache and isn't going to...
12
1654
by: Ken Varn | last post by:
Is there anyway within my web application that I can have all browser caching turned off for all aspx pages sent by my IIS server? I need to have all caching off in order for certain things to work properly, and I can't always rely on the user disabling their cache settings at the browser level. -- ----------------------------------- Ken Varn Senior Software Engineer Diebold Inc.
3
1950
by: lanem | last post by:
I am working on a ASP.NET 2.0 web site that has some PDFs that users can download. I'm using an HTTP module to see if the user has permission to view the PDF before loading it. This all works great. The problem is that once the PDF has been allowed through to the browser, it won't be denied to the next user. So, if one user is allowed to see it and then a user who is not allowed to see it uses the same browser, it comes through for...
21
2324
by: nsimeonov | last post by:
Hello, Does anyone have any idea how Gmail does this? I have a web application and people complain sometimes about some problems and most of the time it turns out it's the browser's cache being full. The application doesn't do anything really fancy and all it does is to set a cookie. I did a search and couldn't find anything except people explainin how I shouldn't do that. Even if the users have to add the server to the trusted zone...
3
1339
by: jlotmar | last post by:
I am currently experiencing a problem whereby browser caching seems to be causing my page to be invalid. I am using a standard DataGrid WebControl which is bound to a DataView object. I use a link in the DataGrid control to go to a details page for the record to edit a number of different fields for the record. After updating the dataset and database, I use a response.redirect (I’ve also tried Server.Transfer) to return to the first...
15
2477
by: bvdb | last post by:
Hello, my web-application uses two frames, one with a list of database records, one with a record detail view. From the detail view there is "mark" function that will mark the respective record in the list frame (with a special color). Now this mark function is meant to toggle the mark status in the list frame, i.e. switch it on with the first click and off with the second. Problem is, the marking works, but the second click will not have...
3
4242
by: Ian Semmel | last post by:
Is there a way to get the Page_Load event to fire if the user clicks the Back button on the browser rather than clicking a hyperlink ?
0
8823
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9530
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9238
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8237
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.