[mochikit] Re: mochikit cache prevention

2006-11-30 Thread Bob Ippolito

On 11/30/06, Jorge Godoy [EMAIL PROTECTED] wrote:
 Bob Ippolito [EMAIL PROTECTED] writes:

  There's always the chance of getting the same random number twice.. A
  timestamp with enough precision is generally better. It's *extremely*
  unlikely that a single user is going to get the same exact timestamp
  twice... there would have to be something seriously wrong with their
  UA for that to happen.

 What's the precision for the timestamp?  If it doesn't get to at least
 milliseconds then it starts being a problem with daylight saving time,
 when the time change occurs.

Date.prototype.getTIme() is defined as an integer number of
milliseconds since the epoch. Daylight savings time or any other
timezone change is totally irrelevant, regardless of the precision.

Even if it was relevant, the chances of doing a request precisely one
hour after a previous request during the one hour per year in which
that happens is a whole lot less than getting the same random number
twice during any session at any time of the year. Especially
considering the fact that most normal people are sleeping during (at
least) the second 2am...

-bob

--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
MochiKit group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~--~~~~--~~--~--~---



[mochikit] Re: mochikit cache prevention

2006-11-30 Thread Diez B. Roggisch
On Wednesday 29 November 2006 18:13, Thomas Hervé wrote:
 Diez B. Roggisch a écrit :
  So - is there any chance such a thing could be made (optionally) part of
  the Async-package?

 If a patch is provided, why not. Until then, you have several options:
 * define the cache control in your web server (with pragma no-cache and
 cache-control).
 * Add an argument to loadJSONdoc(): loadJSONdoc('http://toto',
 {'no-cache': new Date().getTime()})

See the patch attached. 

One turns on cache prevention via 

MochiKit.Async.PREVENT_CACHING_PARAM = 'preventCaching';

The set value is then used as parameter-name. As by your suggestion, I use the 
timestamp.

Works great for me so far. I chose the global variable way because I wanted to 
be as unobtrusive as possible - after all, if you want this, I presume you 
will want it everywhere, and hunting down all async calls that possibly need 
an additional parameter is considerably harder.

Diez


--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
MochiKit group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~--~~~~--~~--~--~---
Index: MochiKit/Async.js
===
--- MochiKit/Async.js	(revision 1225)
+++ MochiKit/Async.js	(working copy)
@@ -365,6 +365,14 @@
 url += ? + qs;
 }
 }
+	if(self.PREVENT_CACHING_PARAM) {
+	  if(url.indexOf(?) =0) {
+	url += ;
+	  } else {
+	url += ?;
+	  }
+	  url += self.PREVENT_CACHING_PARAM + = + new Date().getTime();
+	}
 req.open(opts.method, url, true, opts.username, opts.password);
 if (req.overrideMimeType  opts.mimeType) {
 req.overrideMimeType(opts.mimeType);


[mochikit] Re: mochikit cache prevention

2006-11-30 Thread Bob Ippolito

That's a really bad idea in general. If you want to post, use
something like this::

var d = doXHR(url, {
method: 'POST',
'mimeType': 'text/plain',
'headers': [['Accept', 'application/json']]
}).addCallback(MochiKit.Async.evalJSONRequest);

-bob

On 11/30/06, Martyn Smith [EMAIL PROTECTED] wrote:
 Just as a side note, I found that by POSTING all my data rather than using
 GET (which is the loadJSONDoc default) that browsers (namely IE) stopped
 caching when it shouldn't.

 Perhaps loadJSONDoc could post by default rather than GET?, or perhaps have
 an option/another function for doing this?


 On 12/1/06, Jorge Godoy [EMAIL PROTECTED] wrote:
 
  Bob Ippolito [EMAIL PROTECTED] writes:
 
   Even if it was relevant, the chances of doing a request precisely one
   hour after a previous request during the one hour per year in which
   that happens is a whole lot less than getting the same random number
   twice during any session at any time of the year. Especially
   considering the fact that most normal people are sleeping during (at
   least) the second 2am...
 
  Time changes earlier here in .br, for example.  Anyway, point taken and it
 is
  better using the timestamp then.
 
  --
  Jorge Godoy   [EMAIL PROTECTED]
 
 
 



 --
 Martyn

  


--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
MochiKit group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~--~~~~--~~--~--~---



[mochikit] Re: mochikit cache prevention

2006-11-30 Thread David Shoemaker
All,
I've had success preventing caching in IE and FF by setting these response
headers server-side:
Cache-Control: no-cache, must-revalidate
Expires: Mon, 25 Jul 2005 05:00:00 GMT
Pragma: no-cache

I know this is a javascript-related list, but I prefer to keep as much of
this logic on the server as possible, and this seems to work well.  I'm sure
you can pick any time in the past for the Expires header.

Bob,
Is what you suggested here the official way to POST an xhr with mochikit?
That question comes up all the time on the list and in the irc channel; it
would be nice to be able to point people to a definitive answer (if one
exists...).

Thanks,
David Shoemaker

On 11/30/06, Bob Ippolito [EMAIL PROTECTED] wrote:


 That's a really bad idea in general. If you want to post, use
 something like this::

 var d = doXHR(url, {
 method: 'POST',
 'mimeType': 'text/plain',
 'headers': [['Accept', 'application/json']]
 }).addCallback(MochiKit.Async.evalJSONRequest);

 -bob

 On 11/30/06, Martyn Smith [EMAIL PROTECTED] wrote:
  Just as a side note, I found that by POSTING all my data rather than
 using
  GET (which is the loadJSONDoc default) that browsers (namely IE) stopped
  caching when it shouldn't.
 
  Perhaps loadJSONDoc could post by default rather than GET?, or perhaps
 have
  an option/another function for doing this?
 
 
  On 12/1/06, Jorge Godoy [EMAIL PROTECTED] wrote:
  
   Bob Ippolito [EMAIL PROTECTED] writes:
  
Even if it was relevant, the chances of doing a request precisely
 one
hour after a previous request during the one hour per year in which
that happens is a whole lot less than getting the same random number
twice during any session at any time of the year. Especially
considering the fact that most normal people are sleeping during (at
least) the second 2am...
  
   Time changes earlier here in .br, for example.  Anyway, point taken
 and it
  is
   better using the timestamp then.
  
   --
   Jorge Godoy   [EMAIL PROTECTED]
  
  
  
 
 
 
  --
  Martyn
 
   
 

 



-- 
--- I'd give my right arm to be ambidextrous. ---


--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
MochiKit group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~--~~~~--~~--~--~---


[mochikit] Re: mochikit cache prevention

2006-11-30 Thread Bob Ippolito

doXHR is just sugar for the three or four lines you'd have if you were
dispatching an XMLHttpRequest manually. It doesn't really do anything
of significance. It doesn't really have anything to do with POST
specifically other than the fact that it can be used to construct a
POST request with arbitrary headers and content (just as it can be
used to do a GET or anything else).

-bob

On 11/30/06, David Shoemaker [EMAIL PROTECTED] wrote:
 All,
 I've had success preventing caching in IE and FF by setting these response
 headers server-side:
 Cache-Control: no-cache, must-revalidate
 Expires: Mon, 25 Jul 2005 05:00:00 GMT
 Pragma: no-cache

 I know this is a javascript-related list, but I prefer to keep as much of
 this logic on the server as possible, and this seems to work well.  I'm sure
 you can pick any time in the past for the Expires header.

 Bob,
 Is what you suggested here the official way to POST an xhr with mochikit?
 That question comes up all the time on the list and in the irc channel; it
 would be nice to be able to point people to a definitive answer (if one
 exists...).

 Thanks,
 David Shoemaker


 On 11/30/06, Bob Ippolito [EMAIL PROTECTED] wrote:
 
  That's a really bad idea in general. If you want to post, use
  something like this::
 
  var d = doXHR(url, {
  method: 'POST',
  'mimeType': 'text/plain',
  'headers': [['Accept', 'application/json']]
  }).addCallback(MochiKit.Async.evalJSONRequest);
 
  -bob
 
  On 11/30/06, Martyn Smith [EMAIL PROTECTED] wrote:
   Just as a side note, I found that by POSTING all my data rather than
 using
   GET (which is the loadJSONDoc default) that browsers (namely IE) stopped
   caching when it shouldn't.
  
   Perhaps loadJSONDoc could post by default rather than GET?, or perhaps
 have
   an option/another function for doing this?
  
  
   On 12/1/06, Jorge Godoy [EMAIL PROTECTED] wrote:
   
Bob Ippolito [EMAIL PROTECTED]  writes:
   
 Even if it was relevant, the chances of doing a request precisely
 one
 hour after a previous request during the one hour per year in which
 that happens is a whole lot less than getting the same random number
 twice during any session at any time of the year. Especially
 considering the fact that most normal people are sleeping during (at
 least) the second 2am...
   
Time changes earlier here in .br, for example.  Anyway, point taken
 and it
   is
better using the timestamp then.
   
--
Jorge Godoy   [EMAIL PROTECTED]
   
   
   
  
  
  
   --
   Martyn
  

  
 
   
 



 --
 --- I'd give my right arm to be ambidextrous. ---

--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
MochiKit group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~--~~~~--~~--~--~---



[mochikit] Re: mochikit cache prevention

2006-11-30 Thread Bob Ippolito

On 11/30/06, Lee Eschen [EMAIL PROTECTED] wrote:
 Bob Ippolito wrote:
  That's a really bad idea in general. If you want to post, use
  something like this::
 
  var d = doXHR(url, {
  method: 'POST',
  'mimeType': 'text/plain',
  'headers': [['Accept', 'application/json']]
  }).addCallback(MochiKit.Async.evalJSONRequest);
 
 Bob, can you expand on your comment above?  Why is POSTing a bad idea as
 opposed to GETing?  Why is your code sample a better idea?

POSTing is a fine idea if and only if the server expects it. POSTing
by default is a really bad idea because it's semantically not a POST
operation. It also thwarts caching altogether, when you really only
want to thwart caching for volatile documents. Not all documents are
volatile.

For example, the MochiKit documentation generates an index dynamically
by fetching the XHTML documents and parsing out the function
definitions. These XHTML documents really don't change much at all and
should be cached.

-bob

--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
MochiKit group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~--~~~~--~~--~--~---



[mochikit] Re: mochikit cache prevention

2006-11-29 Thread Thomas Hervé


Diez B. Roggisch a écrit :

 So - is there any chance such a thing could be made (optionally) part of the
 Async-package?

If a patch is provided, why not. Until then, you have several options:
* define the cache control in your web server (with pragma no-cache and
cache-control).
* Add an argument to loadJSONdoc(): loadJSONdoc('http://toto',
{'no-cache': new Date().getTime()})

-- 
Thomas


--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
MochiKit group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~--~~~~--~~--~--~---