Welcome to WebmasterWorld Guest from 54.226.22.192

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

about caching data with header()

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

Preferred Member

10+ Year Member

joined:Mar 11, 2006
posts:379
votes: 0


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');

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

Preferred Member

10+ Year Member

joined:Mar 11, 2006
posts:379
votes: 0


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

Junior Member

10+ Year Member

joined:Dec 13, 2003
posts:109
votes: 0


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.
9:24 pm on Jan 7, 2007 (gmt 0)

Senior Member

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

joined:Nov 12, 2005
posts:5966
votes: 0


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]

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

New User

5+ Year Member

joined:Jan 7, 2007
posts:4
votes: 0


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

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

Senior Member

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

joined:Nov 12, 2005
posts:5966
votes: 0


Hey, welcome to WebmasterWorld, coastie! ;)
12:50 am on Jan 8, 2007 (gmt 0)

New User

5+ Year Member

joined:Jan 7, 2007
posts:4
votes: 0


Hey, welcome to WebmasterWorld, coastie! ;)


Thanks, eelixduppy. Been meaning to register here for some time, just now got around to it.
2:59 pm on Jan 11, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Mar 11, 2006
posts:379
votes: 0


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

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members