bs0d
said... <
i>How did
you get php to
do the
caching?
i got it to do
it wrong
but now i fixed
it, so it's
all good. i
explained what
i did wrong in
the thread on
my forum if
anybody's
interested.
basically, to
get a browser
(or a proxy
server) to
cache your
content, you
have to tell it
when it last
changed. this
is done with
the
Last-Modified
header, and has
to be in the
format 'D, d M
Y H:i:s T' --
i think it also
needs to be
GMT, but i
didn't try any
other time
zone. once a
browser or
proxy receives
a file with
this header, it
sends a
If-Modified-Sin
ce header on
subsequent
requests with
the date it got
in the
Last-Modified
header. now if
your file has
not changed
since the date
in
If-Modified-Sin
ce
($_SERVER['HTT
P_IF_MODIFIED_S
INCE']), you
just send a
header
'HTTP/1.0 304
Not Modified'
and kill your
script. the
browser/proxy
sees that and
uses the cached
copy.
i had a couple
issues that
made this
slightly more
complicated for
me. first is
that all my
stylesheets are
including a php
file which sets
some constants
with the colors
to use (this is
how i have 4
different color
schemes
available). i
put all the
cache control
code in there,
so that was
actually nice

it did make
getting the
correct value
for
Last-Modified
slightly more
complicated
though -- i
have to check
filemtime() on
both the css
file and the
include file,
and use the
more recent
value. also,
my include file
sets some flags
for if the
browser is ie
or opera based
on useragent,
so i don't
want a proxy
server caching
the ie style
and sending it
to opera and
firefox. this
is
(supposedly--i
have no way to
test it)
handled by the
Cache-Control
header, which
is
's-maxage=0,
proxy-revalidea
te' from what
i can tell,
this means that
shared caches
should consider
the file fresh
for 0 seconds,
and that
proxies should
always obey
that rule.
of course if
you don't use
php in your css
files, the
server sends
the appropriate
headers for you

please note
that the above
post is likely
made up in its
entirety. |