homepage Welcome to WebmasterWorld Guest from 54.224.53.192
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
about caching data with header()
asantos

5+ Year Member



 
Msg#: 3210469 posted 4:05 pm on Jan 6, 2007 (gmt 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');

 

asantos

5+ Year Member



 
Msg#: 3210469 posted 7:38 pm on Jan 7, 2007 (gmt 0)

anyone?

Dabu The Dragon

10+ Year Member



 
Msg#: 3210469 posted 8:15 pm on Jan 7, 2007 (gmt 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.

eelixduppy

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



 
Msg#: 3210469 posted 9:24 pm on Jan 7, 2007 (gmt 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]

coastie

5+ Year Member



 
Msg#: 3210469 posted 11:01 pm on Jan 7, 2007 (gmt 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

eelixduppy

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



 
Msg#: 3210469 posted 11:30 pm on Jan 7, 2007 (gmt 0)

Hey, welcome to WebmasterWorld, coastie! ;)

coastie

5+ Year Member



 
Msg#: 3210469 posted 12:50 am on Jan 8, 2007 (gmt 0)

Hey, welcome to WebmasterWorld, coastie! ;)


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

asantos

5+ Year Member



 
Msg#: 3210469 posted 2:59 pm on Jan 11, 2007 (gmt 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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved