Welcome to WebmasterWorld Guest from 54.163.40.152

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

about caching data with header()

     

asantos

4:05 pm on Jan 6, 2007 (gmt 0)

5+ Year Member



hi. i am generating a javascript file through php (because i need to grab some data from my db).

the data of the generated JS, could be -easily- get used for the next 3 days by the visitor.

what headers should i use in order to accomplish that? this are my actual headers:

header('Expires: '.gmdate('D, d M Y H:i:s',time()+(60*60*24*3)).' GMT');
header('Content-type: application/x-javascript');

asantos

7:38 pm on Jan 7, 2007 (gmt 0)

5+ Year Member



anyone?

Dabu The Dragon

8:15 pm on Jan 7, 2007 (gmt 0)

10+ Year Member



Instead of counting time with JS, would use PHP to count time. Maybe something along the lines of srand() microtime(). If I am understanding your question clearly.

eelixduppy

9:24 pm on Jan 7, 2007 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



You might want to take a peek at
cache-control
and
Last-Modified
as they will also aid you in this.

Hypertext Transfer Protocol [faqs.org]

coastie

11:01 pm on Jan 7, 2007 (gmt 0)

5+ Year Member



This is taken from a script I use to compress web pages, I broke out the header/cache stuff:

(the style codes aren't working, at least in preview mode, so I'm leaving the formatting alone)

// send the requisite header information and character set
header ("content-type: application/x-javascript;");

// check cached credentials and reprocess accordingly
header ("cache-control: must-revalidate");

// set variable for duration of cached content
$offset = 60 * 60 * 72; //sec:min:hrs you said 3 days, right?

// set variable specifying format of expiration header
$expire = "expires: " . gmdate ("D, d M Y H:i:s", time() + $offset) . " GMT";

// send cache expiration header to the client broswer
header ($expire);

That would probably do the job. Don't know who originally wrote this, it's found on several sites.

ta

eelixduppy

11:30 pm on Jan 7, 2007 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



Hey, welcome to WebmasterWorld, coastie! ;)

coastie

12:50 am on Jan 8, 2007 (gmt 0)

5+ Year Member



Hey, welcome to WebmasterWorld, coastie! ;)


Thanks, eelixduppy. Been meaning to register here for some time, just now got around to it.

asantos

2:59 pm on Jan 11, 2007 (gmt 0)

5+ Year Member



Coastie, will that code guarantee that:

*) The "js" will get cached by the visitor's browser for three days. That means that next time he visits the website my website wont have to re-generate the whole javascript code

?

Thanks,
Andres

 

Featured Threads

Hot Threads This Week

Hot Threads This Month