From: Lorenzo A. <l.a...@ti...> - 2005-06-16 15:28:54
|
Hi Harry, I was wondering if the JPSpan headers can be cached into a standalone .js file instead of being included in the html page every time. I haven't looked at the contents, so I don't know if the generated code depends on the browser or something; if not, is there any issue I should be aware of, or can I safely cache the headers? I mean: the value returned by JPSpan_Includes_Fetch(); Thanks in advance All the best, -- Lorenzo Alberton http://pear.php.net/user/quipo |
From: Harry F. <hf...@gm...> - 2005-06-20 12:15:25
|
Hi Lorenzo (and good to hear from you again), > I was wondering if the JPSpan headers > can be cached into a standalone .js file > instead of being included in the html page > every time. Basically yes. >=20 > I haven't looked at the contents, so I don't > know if the generated code depends on the browser > or something; if not, is there any issue > I should be aware of, or can I safely cache the headers? > I mean: the value returned by JPSpan_Includes_Fetch(); One example: http://jpspan.sourceforge.net/examples/postoffice_server.php?c= lient - this Javascript is basically static and the same is delivered irrespective of client browser etc. etc. As long as the PHP class(es) that is was generated for do not change, the client is still valid. You should be able to cache is both server side if you desire and client side with HTTP headers. All the best, Harry |
From: Harry F. <hf...@gm...> - 2005-06-20 12:23:04
|
One further thing I forgot to mention (which may or may not be obvious) - the actual server responses to "JPSpan" micro-requests are not cacheable (in fact the PostOffice server sends "dont cache" headers), although they are Javascript - as they contain live data they are always regarded as "fresh". If you want control over those headers, check the argument you can pass to JPSpan_Server_PostOffice::serve() - pass FALSE and it sends no headers. There's some detailed issues here related to XMLHttpRequest, if you're interested (but don't worry if you're not) I tried to detail here; http://jpspan.sourceforge.net/wiki/doku.php?id=3Djavascript:xmlhttprequest:= behaviour#http_caching http://jpspan.sourceforge.net/wiki/doku.php?id=3Djavascript:xmlhttprequest:= behaviour:httpheaders#conditional_get On 6/20/05, Harry Fuecks <hf...@gm...> wrote: > Hi Lorenzo (and good to hear from you again), >=20 > > I was wondering if the JPSpan headers > > can be cached into a standalone .js file > > instead of being included in the html page > > every time. >=20 > Basically yes. >=20 > > > > I haven't looked at the contents, so I don't > > know if the generated code depends on the browser > > or something; if not, is there any issue > > I should be aware of, or can I safely cache the headers? > > I mean: the value returned by JPSpan_Includes_Fetch(); >=20 > One example: http://jpspan.sourceforge.net/examples/postoffice_server.php= ?client > - this Javascript is basically static and the same is delivered > irrespective of client browser etc. etc. >=20 > As long as the PHP class(es) that is was generated for do not change, > the client is still valid. You should be able to cache is both server > side if you desire and client side with HTTP headers. >=20 > All the best, >=20 > Harry > |
From: Lorenzo A. <l.a...@ti...> - 2005-06-22 12:35:25
|
Hi Harry, thanks a lot for your detailed answer. It's nice to hear you again, apparently I'm not the only one to miss your blog posts ;) http://www.sitepoint.com/forums/showthread.php?t=272338 >>>I was wondering if the JPSpan headers >>>can be cached into a standalone .js file >>>instead of being included in the html page >>>every time. >> >>One example: http://jpspan.sourceforge.net/examples/postoffice_server.php?client >>- this Javascript is basically static and the same is delivered >>irrespective of client browser etc. etc. that's the answer I was looking forward to, I guess. >>As long as the PHP class(es) that is was generated for do not change, >>the client is still valid. You should be able to cache is both server >>side if you desire and client side with HTTP headers. > > One further thing I forgot to mention (which may or may not be > obvious) - the actual server responses to "JPSpan" micro-requests are > not cacheable (in fact the PostOffice server sends "dont cache" > headers), although they are Javascript - as they contain live data > they are always regarded as "fresh". If you want control over those > headers, check the argument you can pass to > JPSpan_Server_PostOffice::serve() - pass FALSE and it sends no > headers. I lost you here :-) I guess the micro-requests headers you're referring to in your last paragraph are the headers sent on an ajax request (i.e. when the user triggers some ajax action), not on page load, right? I.e. ATM I'm only interested in caching the js code generated on page load (JPSpan_Includes_Fetch()), while the micro-requests can stay uncached. In this case, I can leave the JPSpan_Server_PostOffice::serve() parameter to TRUE, so the micro-requests are not cached, right? And to make the page cache effective, can I leave the page headers out? ================================================= function getJpspanHeaders() { define('JPSPAN_RENDER_FORMATTING', false); require_once LIB_DIR.'/JPSpan.php'; require_once JPSPAN . 'Include.php'; JPSpan_Include_Register('util/data.js'); JPSpan_Include_Register('encode/php.js'); JPSpan_Include_Register('request/post.js'); /* //commented these headers to make the js code cacheable header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate('D, d M Y H:i:s') . "GMT"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); */ return JPSpan_Includes_Fetch(); } ================================================= To be extra-clear: I only want to optimize the page load time, while the micro-requests handling time doesn't worry me ATM. TIA All the best, -- Lorenzo Alberton http://pear.php.net/user/quipo |
From: Harry F. <hf...@gm...> - 2005-06-22 14:04:26
|
> thanks a lot for your detailed answer. > It's nice to hear you again, apparently > I'm not the only one to miss your blog posts ;) > http://www.sitepoint.com/forums/showthread.php?t=3D272338 Thanks for link - nice to be missed. My poor but real excuse is time and occasionally motivation ;). > I lost you here :-) >=20 > I guess the micro-requests headers you're referring to > in your last paragraph are the headers sent on an ajax > request (i.e. when the user triggers some ajax action), > not on page load, right? Right. My fault - providing more information than needed and creating confusion to try eliminate confusion. The "AJAX" responses from JPSpan are themselves javascript which is eval'd client side (vs. XML / SOAP / WDDX whatever). JPSpan always sends "dont cache" HTTP headers for AJAX responses. > I.e. ATM I'm only interested in caching the js code > generated on page load (JPSpan_Includes_Fetch()), > while the micro-requests can stay uncached. > In this case, I can leave the JPSpan_Server_PostOffice::serve() > parameter to TRUE, so the micro-requests are not cached, right? Right > And to make the page cache effective, can I leave the page > headers out? Right - any "dont cache" HTTP headers in the examples that cause the generated clients not to be cached are really only for my benefit, while hacking on JPSpan. >=20 > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > function getJpspanHeaders() > { > define('JPSPAN_RENDER_FORMATTING', false); > require_once LIB_DIR.'/JPSpan.php'; > require_once JPSPAN . 'Include.php'; > JPSpan_Include_Register('util/data.js'); > JPSpan_Include_Register('encode/php.js'); > JPSpan_Include_Register('request/post.js'); >=20 > /* > //commented these headers to make the js code cacheable > header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); > header("Last-Modified: " . gmdate('D, d M Y H:i:s') . "GMT"); > header("Cache-Control: no-cache, must-revalidate"); > header("Pragma: no-cache"); > */ >=20 > return JPSpan_Includes_Fetch(); > } > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >=20 > To be extra-clear: I only want to optimize the page load time, > while the micro-requests handling time doesn't worry me ATM. The above code is correct - for a given browser the generated client will be cached correctly. A further optimization might be to cache server-side as well - the Javascript "compression" I copied and pasted is slow so doing this would save some server CPU cycles (otherwise it will be re-compressed for the first request for every new visitor / browser). >=20 > TIA >=20 > All the best, > -- > Lorenzo Alberton > http://pear.php.net/user/quipo > |
From: Lorenzo A. <l.a...@ti...> - 2005-06-22 14:52:22
|
Hi Harry, >>I lost you here :-) >> > My fault - providing more information than needed and creating > confusion to try eliminate confusion. LOL :-D > JPSpan always sends "dont cache" HTTP headers for AJAX responses. great >>To be extra-clear: I only want to optimize the page load time, >>while the micro-requests handling time doesn't worry me ATM. > > The above code is correct - for a given browser the generated client > will be cached correctly. A further optimization might be to cache > server-side as well - the Javascript "compression" I copied and pasted which js compression? > is slow so doing this would save some server CPU cycles (otherwise it > will be re-compressed for the first request for every new visitor / > browser). Thank you! Cheers, -- Lorenzo Alberton http://pear.php.net/user/quipo |
From: Harry F. <hf...@gm...> - 2005-06-24 18:47:05
|
On 6/22/05, Lorenzo Alberton <l.a...@ti...> wrote: > Hi Harry, >=20 > >>I lost you here :-) > >> > > My fault - providing more information than needed and creating > > confusion to try eliminate confusion. >=20 > LOL :-D >=20 > > JPSpan always sends "dont cache" HTTP headers for AJAX responses. >=20 > great One further detail you don't need there. I'm even more confused - made a change in the release before last requiring that AJAX requests are always made with the POST method - in other words the browser won't cache anything anyway... >=20 >=20 > >>To be extra-clear: I only want to optimize the page load time, > >>while the micro-requests handling time doesn't worry me ATM. > > > > The above code is correct - for a given browser the generated client > > will be cached correctly. A further optimization might be to cache > > server-side as well - the Javascript "compression" I copied and pasted >=20 > which js compression? Ah - if you check out the constant JPSPAN_INCLUDE_COMPRESS in Include.php, this controls the "compression" (which happens server side) - the actual compression routine is defined in Script.php - basically it just eliminates whitespace. Need to re-write this eventually. >=20 > > is slow so doing this would save some server CPU cycles (otherwise it > > will be re-compressed for the first request for every new visitor / > > browser). >=20 >=20 > Thank you! >=20 > Cheers, > -- > Lorenzo Alberton > http://pear.php.net/user/quipo > |
From: Lorenzo A. <l.a...@ti...> - 2005-06-28 19:12:25
|
Hi Harry, >>>The above code is correct - for a given browser the generated client >>>will be cached correctly. A further optimization might be to cache >>>server-side as well - the Javascript "compression" I copied and pasted >> >>which js compression? > > Ah - if you check out the constant JPSPAN_INCLUDE_COMPRESS in > Include.php, this controls the "compression" (which happens server > side) - the actual compression routine is defined in Script.php - > basically it just eliminates whitespace. Need to re-write this > eventually. thanks for the tip, I didn't know about it. All the best, -- Lorenzo Alberton http://pear.php.net/user/quipo |