Hi,
Date.getTime is in milliseconds since the epoch, but browsers rarely
support the full resolution. On my machine, Firefox/2.0/Win32, the
minimum resolution is about 10 milliseconds. You can test this by:
var y = (new Date).getTime() ;
for ( var x = 0 ; x < 100000 ; x++ ) {
if ( y != (new Date).getTime() ) break ;
}
alert( x + ":" + (new Date).getTime() - y ) ;
Which should give 1:1 but on my machine gives about 500:10.
So multiple calls to getTime can return the same number, although if
you're using it for network stuff, the latency will probably stop this
from being a problem. When I need a unique number I append a global
counter onto getTime, like:
var newunique = (new Date).getTime() + "" + (unique++) ;
You can't just use a global counter, because restarting a browser or
reloading the page will give non-unique values. It's still not
strongly unique across multiple windows, but it's not too bad.
I'm against any attempt to make having a dontCache parameter the
default - cherrypy throws when receiveing a method call with an
unknown parameter name, and I suspect other frameworks will do the
same.
A much better solution is server side - IE seems to ignore plenty of
headers which should make it not cache, but this combination seems to
work:
request.setHeader( 'Expires', "Mon, 26 Jul 1997 05:00:00 GMT" )
request.setHeader( 'Cache-Control', 'no-cache, must-revalidate' )
request.setHeader( 'Pragma', 'no-cache' )
Caching is a general issue, not just related to XMLHttpRequest - IE
will also often ignore most caching headers for images, and other
dynamically inserted elements, so server-side headers or src mangling
is needed for them too.
Hamish Friedlander,
Mind Control Dogs
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"MochiKit" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---